Hi: I notice that the obj.is_a? method does not work on a class constant. It only works on an instance of the class. Is this the way it should work? Do I need to create a loop checking using the superclass method to check the inheritance of a class or is there an easier way? Thanks, Bob Rice
Have you tried kind_of? method, i.e. class AnArray < Array end a = AnArray.new a.kind_of? Array will return true a.kind_of? String will return false assuming I haven't miss understood your question. Dave. On 19 Jan 2011, at 21:06, Robert Rice wrote:
Hi:
I notice that the obj.is_a? method does not work on a class constant. It only works on an instance of the class.
Is this the way it should work? Do I need to create a loop checking using the superclass method to check the inheritance of a class or is there an easier way?
Thanks, Bob Rice
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi Dave: Thanks for the reply. You instantiated AnArray. Try this: class AnArray < Array; end AnArray.kind_of?( Array ) will return false is_a? doesn't work on the class object. I don't know if it supposed to but other than creating an instance the only alternative is a loop requesting the superclass. AnArray.superclass == Array will return true Bob Rice On Jan 19, 2011, at 4:14 PM, Dave Baldwin wrote:
Have you tried kind_of? method,
i.e.
class AnArray < Array end
a = AnArray.new
a.kind_of? Array will return true a.kind_of? String will return false
assuming I haven't miss understood your question.
Dave.
On 19 Jan 2011, at 21:06, Robert Rice wrote:
Hi:
I notice that the obj.is_a? method does not work on a class constant. It only works on an instance of the class.
Is this the way it should work? Do I need to create a loop checking using the superclass method to check the inheritance of a class or is there an easier way?
Thanks, Bob Rice
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 2011-01-19, at 20:50 , Robert Rice wrote:
You instantiated AnArray. Try this:
class AnArray < Array; end
AnArray.kind_of?( Array ) will return false
Is this what you're looking for? $ macirb irb(main):001:0> class AnArray < Array; end => nil irb(main):002:0> AnArray <= Array => true
Hi Caio: Yep. That will work. I didn't find the <= class method in the RDoc. Thanks, Bob Rice On Jan 19, 2011, at 6:15 PM, Caio Chassot wrote:
On 2011-01-19, at 20:50 , Robert Rice wrote:
You instantiated AnArray. Try this:
class AnArray < Array; end
AnArray.kind_of?( Array ) will return false
Is this what you're looking for?
$ macirb irb(main):001:0> class AnArray < Array; end => nil irb(main):002:0> AnArray <= Array => true
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Wed, Jan 19, 2011 at 5:15 PM, Caio Chassot <lists@caiochassot.com> wrote:
On 2011-01-19, at 20:50 , Robert Rice wrote:
You instantiated AnArray. Try this:
class AnArray < Array; end
AnArray.kind_of?( Array ) will return false
Is this what you're looking for?
$ macirb irb(main):001:0> class AnArray < Array; end => nil irb(main):002:0> AnArray <= Array => true
Or: AnArray.ancestors.include? Array
Hi Eric: Thanks, the ancestors method will work better. Do class objects inherit all of the Module methods? Bob Rice On Jan 29, 2011, at 1:22 AM, Eric Christopherson wrote:
On Wed, Jan 19, 2011 at 5:15 PM, Caio Chassot <lists@caiochassot.com> wrote:
On 2011-01-19, at 20:50 , Robert Rice wrote:
You instantiated AnArray. Try this:
class AnArray < Array; end
AnArray.kind_of?( Array ) will return false
Is this what you're looking for?
$ macirb irb(main):001:0> class AnArray < Array; end => nil irb(main):002:0> AnArray <= Array => true
Or:
AnArray.ancestors.include? Array _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Sat, Jan 29, 2011 at 5:15 PM, Robert Rice <rice.audio@pobox.com> wrote:
Hi Eric:
Thanks, the ancestors method will work better.
Do class objects inherit all of the Module methods?
Sorry, I didn't see your message before (assuming you were asking me specifically). I hope someone else answers this, because I'm not sure. In others Rubys, Class is a subclass of Module, so all of Module's methods should be inherited; but I'm not sure about MacRuby.
On Thu, Feb 3, 2011 at 5:28 PM, Eric Christopherson <echristopherson@gmail.com> wrote:
On Sat, Jan 29, 2011 at 5:15 PM, Robert Rice <rice.audio@pobox.com> wrote:
Hi Eric:
Thanks, the ancestors method will work better.
Do class objects inherit all of the Module methods?
Sorry, I didn't see your message before (assuming you were asking me specifically).
I hope someone else answers this, because I'm not sure. In others Rubys, Class is a subclass of Module, so all of Module's methods should be inherited; but I'm not sure about MacRuby.
Class is a subclass of Module in MacRuby too. And it does inherit Module's methods. You can prove this for yourself in any given Ruby: Module.methods - Class.methods It will return [] if Class has every method that Module does. — Chuck
participants (5)
-
Caio Chassot
-
Charles Steinman
-
Dave Baldwin
-
Eric Christopherson
-
Robert Rice