From: dmg2009@... Date: 2009-12-15T06:00:08+09:00 Subject: Re: ruby eval magic On Dec 14, 11:51 am, Brian Candler wrote: > When Ruby code is executing, there are two bits of state which are > maintained: > - the current object, which is exposed as 'self' > - the current class, where instance methods are defined. This is pretty > well hidden, but sometimes it matters. > > Try the following code: > >     class Foo; end > >     Foo.class_eval "def bar; puts 'Hello!'; end" > >     Foo.new.bar > > If you change class_eval to instance_eval, it won't work as shown. In > fact you'll make a class method on Foo (Foo.bar) Oh, I see. Yes, the context matter when defining methods. Thank you very much!