Displaying 20 results from an estimated 190 matches for "is_a".
Did you mean:
ip_a
2012 Sep 22
4
Class, Module, Object
...ule
false
=> nil
>> Object.parent
=> Object
The above indicates that the Class object instance inherits from the
Module object instance and the Module object instance inherits from
Object. And Object doesn''t inherit from anything.
So why do these return true:
>> Module.is_a?(Class)
=> true
>> Object.is_a?(Module)
=> true
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe fr...
2010 Jul 13
2
[Rspec] Difference between stub and message expectation with any_number_of_times
I''m wondering what''s the difference between stub and message expectation
with any_number_of_times, for example:
myMock = mock("mymock")
myMock.stub!(:is_a?).with(MyClass).and_return(false)
and
myMock = mock("mymock")
myMock.should_receive(:is_a?).with(MyClass).any_number_of_times.and_return(false)
because is_a? may not be called at all, it just like a stub. Is my
understanding correct?
Is there any guide how to use stub and message expe...
2011 May 25
1
rake task: uninitialized constant
...do
UnsafeBuilding.delete_all
puts "Creating unsafe_buildings..."
lines = FasterCSV.read(''/home/user/Docs/pericolanti'')
lines.each do |row|
if row.any?
# controllo che row[10] e row[11] non siano stringhe
barrier_meters = row[10] if row[10].is_a?(Float) or
row[10].is_a?(Integer)
square_meters_public_land = row[11] if row[11].is_a?(Float) or
row[11].is_a?(Integer)
practice_number = row[17].to_i
practice_date = parse_date_string(row[3])
practice_new_date = parse_date_string(row[3])
inspection_date = parse_...
2011 May 13
4
unexpected results when extending methods to class Class and class Object
Hey all,
There''s a core Class class and core Object class in Ruby library:
http://www.ruby-doc.org/core/classes/Object.html
http://www.ruby-doc.org/core/classes/Class.html
First, let''s resolve the simple distinction between an Object and Class
as envisioned by Smalltalk but within the Ruby context:
#A class is a template used to define methods and properties
class Hello
2006 Feb 01
1
Class of uploated file
...by also other class?
I need to know this because i have my own validation of file kind and
when is mime type invalid then i want to put msg to record.errors and i
also want to dont upload this file in next step by my upload method so i
call in validation on invalid type somethig like
if file.is_a?(StringIO) then
file.string = ''''
file.close
file = nil
record.errors.add attr, ''STRINGIO''
elsif file.is_a?(File) then
File.unlink(file.path)
file = nil
record.errors.add attr, ''FILE''
elsif file.is_a?(Te...
2010 Feb 10
6
validation problems
Hi, there.
I have two validations in the model:
validates_numericality_of :value, :only_integer=>true,
:allow_blank=>true
validates_size_of :value, :is=>9, :message=>"must be 5-digit number",
:if=>Proc.new{|u| u.value.is_a?(Numeric)}
They work as expected except when the :value is character/string like
"a" "abc", the second validation will also output error message "must be
5-digit number". What I want is the second validation displays error
message only when the :value is a number. I...
2007 Mar 12
10
using mocha with rspec
Hi folks.
I''ve just started using rspec and I have to say it''s very nice. The
thing is, I prefer mocha''s mocking dialect. So I thought a simple
require ''mocha'' would set me up.
Unfortunately, rspec does all its goodness using do/end blocks in
anonymous classes, so it wasn''t quite that obvious.
Anyway, here is the incantation I ended up
2010 Apr 21
4
Accessing the router from a helper
I find manually accessing the router to be quite ugly below. Is there
a more direct way to access it?
module ApplicationHelper
def menu_item text, url = nil
routes = ActionController::Routing::Routes
url = if url
if url.is_a? String
url
else
routes.generate url
end
else
routes.generate :controller => text
end
unless text.is_a? String
text = t text
end
active = request.request_uri == url
"<li #{'...
2006 Sep 22
2
foo.expects(:blah).returns(10).then(11) syntax
...= RuntimeError, message = nil)
- @return_value = lambda{ raise exception, message }
+ return_value << lambda{ raise exception, message }
self
end
def invoke
@invoked += 1
yield(*@parameters_to_yield) if yield? and block_given?
- @return_value.is_a?(Proc) ? @return_value.call : @return_value
+ this_return = return_value.size > 1 ? return_value.shift :
return_value.first
+ this_return.is_a?(Proc) ? this_return.call : this_return
end
def verify
2007 Dec 28
9
lost connection 2.0
I lost my "connection lost" error.. but now I''ve got a "Mysql::Error:
MySQL server has gone away" error..
It comes from:
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract_adapter.rb:128:in ''log''.
I''m not sure if Rails / BackgroundRb uses it .. but i''ve got the mysql
(2.7) gem
2007 Oct 08
1
How to get database adapter type programmatically in rails?
...nt for Mysql and Oracle, so I have to get
database adapter type programmatically in my codes to process
different native SQL statements. I haven''t found any document for this
situation. After some research, I have found a way to do so like
following:
if ActiveRecord::Base::connection.is_a?
(ActiveRecord::ConnectionAdapters::OracleAdapter)
{Process native Oracle SQL statements}
else if ActiveRecord::Base::connection.is_a?
(ActiveRecord::ConnectionAdapters::MysqlAdapter)
{Process natvie Mysql SQL statements}
end
After test, it works. But I am wondering if this i...
2006 Oct 19
3
Selecting datetime values from SQL Server (year < 1970)
...ll that generates a SELECT * type query against a table
with a DATETIME column in SQL Server whose value occurs before 1970 will
fail, because of the coercion of SQL Server datetime types to Time
values in Ruby.
See sqlserver_adapter.rb line 490
(record[col] = record[col].to_time if record[col].is_a? DBI::Timestamp)
If I remove the coercion (just commenting out that line), I can
successfully execute these find() calls.
I have a couple of questions:
1) Does anyone know of any adverse effects that I will incur by doing
this?
2) Does anyone know when this will be resolved in the sqlserver_ad...
2012 Sep 20
2
append_features(mod)
append_features(mod)
The documentation says:
When this module is included in another, Ruby calls append_features in
this module, passing it the receiving module in mod. Ruby’s default
implementation is to add the constants, methods, and module variables
of this module to mod if this module has not already been added to mod
or one of its ancestors. See also Module#include.
What if this module is
2007 Aug 19
4
describing a mock_model as being an instance
Is there a built-in way of describing a mock_model as being an instance, beyond
stubbing the eval("Object.methods - Object.new.methods") methods to throw
NoMethodErrors?
Edward
2012 Jul 05
1
hash to_yaml in erb template not giving valid yaml
...9;t provide a valid yaml format if I
dump my scope to hash and convert to_yaml.
file {
"/etc/mcollective/facts.yaml" :
owner => root,
group => root,
mode => 400,
loglevel => debug,
#content => inline_template("<%= scope.to_hash.reject { |k,v| !(
k.is_a?(String) && v.is_a?(String) ) }.to_yaml %>"),
#content => inline_template("<%= { \"a\" => 1, \"b\"=> 2}.to_yaml %>"),
content =>
inline_template("<%= facts = {}; scope.to_hash.each_pair {|k,v|
facts[k.to_s] = v.to_s u...
2008 Apr 25
4
win32-mmap test failures
Hi all,
This is odd. It looks to me like we have all 4 variations of memcpy set
in Windows::MSVCRT::Buffer but somehow this one creeps up. I actually
noticed it in a few cases with that earlier mmap sub/replace example,
but I wasn''t sure what was happening.
Note that windows-api 0.2.3 and windows-pr-0.8.3 are the latest versions
in CVS, but this happens with windows-api-0.2.2 and
2006 Mar 08
1
indexing a document object fails
.../config/../vendor/ferret/index/index.rb:238:in
`synchronize''
C:/dev/workspace/fred/config/../vendor/ferret/index/index.rb:238:in `<<''
C:\dev\workspace\fred/test/unit/user_test.rb:56:in
`test_index_document_sanity_check''
Which appears to be caused because
elsif doc.is_a?(Document)
is expecting a Ferret::Document rather than
Ferret::Document::Document. When I change this line to
elsif doc.is_a?(Document::Document)
I get past the indexing part, and am able to retrieve the document...i.e.
index.search_each("*") do |score_doc, score|
p index.doc(score...
2006 Sep 29
1
yielding consecutive values
...(revision 62)
+++ lib/mocha/expectation.rb (working copy)
@@ -217,7 +217,12 @@
def invoke
@invoked += 1
- yield(*@parameters_to_yield) if yield? and block_given?
+ if yield? and block_given?
+ params = @parameters_to_yield.collect do |element|
+ element.is_a?(Proc) ? element.call : element
+ end
+ yield(*params)
+ end
@return_value.is_a?(Proc) ? @return_value.call : @return_value
end
This test passes also, but I didn''t think it was necessary for the
suite...
def test_should_yield_with_block_result_1123...
2007 Oct 21
7
exact exceptions in rescue_from
...ates them with handlers.
When an exception is raised there''s a name lookup, and if an entry is
found its handler is invoked. In particular rescue_from does not
emulate Ruby''s rescue semantics with regard to inheritance.
Which is the rationale? Don''t you think taking is_a? and declaration
order into account would provide a better (expected) usage? I could
write a patch in that case.
-- fxn
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To po...
2006 Mar 04
6
Determine if a value is an instance of String , or Array , or...
each loop inside a mixed hash
I need to determine if the value is an instance of String
How ?
hash.each do |k,v|
if v ( instance of ) String
hash[ k ] = v.capitalize
enf
end