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." <lists / ruby-forum.com> 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)
>    #=> #<UnboundMethod: Cow(Animal)#bark>
>
>    class Cow
>      bark
>    end
>    #=> NameError: undefined local variable or method `bark' for
>Cow:Class
>    #        from (irb):11:in `<class:Cow>'
>    #        from (irb):10
>    #        from C:/Ruby193/bin/irb:12:in `<main>'
>
>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)
>    #=> #<UnboundMethod: Object#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/.
>