From: Rick DeNatale Date: 2007-10-26T06:36:28+09:00 Subject: Re: Need help understanding metaclassing On 10/25/07, Chris Czub wrote: > Daniel Waite wrote: > > That's the same code as above. Still doesn't work though. =) > > Nope, it's c.eat instead of cs.eat... works for me! :) > -- Right. This is a slightly different case that I had described. In my example class Foo metaclass.instance_eval {define_method(:bar) {"bar"}} end It's Foo's singleton/metaclass which get the define_method call. Whereas this new case is equivalent to c = Creature.new c.singleton.instance_eval {define_method(:eat) {puts "You eat"}} So in my case, the class Foo ends up with a new method, i.e. a class method since Foo is a class, but c ends up with a new singleton (instance) method. And if you did c.class.instance_eval{define_method(:walk) {puts "You walk"}} An instance method would be created which would be invocable for all instances of Creature, because this is the same as Creature.instance)_eval ... -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/