From: Brian Candler Date: 2003-03-27T21:56:42+09:00 Subject: Re: What are the differences between Ruby's blocks and Python's lambdas? On Thu, Mar 27, 2003 at 09:07:47PM +0900, ts wrote: > >>>>> "B" == Brian Candler writes: > > B> self.class.instance_eval { define_method(:pp, pp) } > > class << self; self end > > give you the singleton class That's fine, but then how do I define the method in the singleton class rather than in the parent class? I can't use 'def' because the local variable pp drops out of scope. class Foo def addmeth(m,x) self.class.instance_eval { define_method(m,x) } end end a = Foo.new b = Foo.new class <> 11 p b.pp(10) # >> 11 (Oops, I didn't want that) Regards, Brian.