sample = [1,2,3]
p sample.class #=> Array
p sample.class.is_a?(Array) #=> false
Sure. sample.class is Array and Array.class is Class.
Sample.class.is_a? (Array) means mostly the same as "is the class of
sample.class Array?". Becaue class of the sample.class is Array not
Class you get false here.
But: sample.is_a? (Array) #=> true
p sample.class.is_a?(Array.class) #=> true (why???)
Class is Class.
I guess you need to understand the difference between sample.is_a? and
sample.class.is_a?
sample = [1,2,3]
p sample.class #=> Array
p sample.is_a?(Array) #=> true
isa? makes checks with .class in the Background automagically.
so what is exactly happening when I type
sample.class.is_a?...
i think it does a check with samle.class.class in the Background wich results in Class
irb(main):001:0> class A
irb(main):002:1> end
=> nil
irb(main):003:0> a = A.new
=> #<A:0x2f8b4b4>
irb(main):004:0> a.class
=> A
irb(main):005:0> a.class.is_a? A
=> false
irb(main):006:0> a.class.class
=> Class
irb(main):007:0> A.class
=> Class
that actually means 'A.class is_a? A' which is not true since A.class is
Class.
That's not quite right. a.class doesn't test A.class; it tests A. So
this:
a.class.is_a? A
is the same as:
A.is_a? A
which is not true.
David
···
On Fri, 22 Dec 2006, Peter Szinek wrote:
--
Q. What's a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
Also, the Pick Axe book has a section on the ruby object model that I thought was really helpful learning this stuff. There's a dichotomy between instance and class objects that I wasn't aware of until I read it.
-Mat
···
On Dec 22, 2006, at 6:10 AM, Spitfire wrote:
Peter Szinek wrote:
a 'is-an' A. you ask for this with
a.is_a? A
When you are asking
a.class.is_a? A
that actually means 'A.class is_a? A' which is not true since A.class is
Class.