"trans. (T. Onoma)" <transami / runbox.com> schrieb im Newsbeitrag 
news:200409110701.54011.transami / runbox.com...
> On Saturday 11 September 2004 05:48 am, Hal Fulton wrote:
>> OK, I have this variable called box.
>>
>> I want to define a singleton method xy on it. No problem.
>>
>> However, I need a closure. So I need to use define_method
>> rather than def.
>>
>> This is how I did it:
>>
>>    class << box; self; end.class_eval { define_method(:xy) {[x,y]} }
>>
>> Surely there is an easier way??
>
> Off the top of my head I use a common lib:
>
> module Kernal
>
>  def metaclass
>    (class << self; self; end)
>  end
>
>  def metaclass_eval(&block)
>    (class << self; self; end).class_eval(&block)
>  end
>
>  def define_singleton(meth, &block)
>    metaclass_eval { define_method(meth, &block) }
>  end
>
> end

Good!  I'd just put it into class Object instead of module Kernel.  That's a 
more appropriate place IMHO.  Also "metaclass" seems the wrong term in this 
case, although I can see why you didn't want to use "singleton_class"...

Regards

    robert