From: "D. Deryl Downey" Date: 2013-03-03T02:54:08+09:00 Subject: Re: Confusion in instance method calls of super class from subclass Why do you think? You added #talk to Object, Foo inherits from Object, so it works. On 3/2/13 12:42 PM, "Kumar R." wrote: >I was just playing to see the instance method calls from the subclass >and used the below code of my test: > > class Animal > def bark > p "hukkhh" > end > end > #=> nil > > class Cow < Animal > end > #=> nil > > Cow.public_instance_method(:bark) > #=> # > > class Cow > bark > end > #=> NameError: undefined local variable or method `bark' for >Cow:Class > # from (irb):11:in `' > # from (irb):10 > # from C:/Ruby193/bin/irb:12:in `
' > >From that code I was confirmed that instance method can't be executed >without the object instance of the respective class. > >But then I tried below code: > > def talk > p "hi" > end > #=> nil > > Object.public_instance_method(:talk) > #=> # > > class Foo > talk > end > # prints: hi > #=> "hi" > >Here the output made me confused with my first test code output. > >Could anyone help me to understand the fact behind these above? > >-- >Posted via http://www.ruby-forum.com/. >