From: Sergey Volkov Date: 2006-05-11T16:39:20+09:00 Subject: Re: plz help with binding This is cool! But not for average (read big enterprise) level programmer :( How can I follow 'keep it simple, stupid!' approach with Ruby metaprogramming? How many Ruby programmers can reproduce this code with easy? Can such code code be supported in production environment? I'm not asking, I'm crying! I'd like to ask Matz: give me real lexical closure and clean up meta class mess, please!!! Or should we admit, that Ruby metaprogramming is for real programmers only? Or I'm just plain stupid? Please advise; thanks bests Sergey ----- Original Message ----- From: To: "ruby-talk ML" Sent: Thursday, May 11, 2006 2:11 AM Subject: Re: plz help with binding > On Thu, 11 May 2006, Sergey Volkov wrote: > >> Now I'm trying to create instance-var-less storage: > > an even trickier way: > > harp:~ > cat a.rb > class C > def self.arr_meth m > m = m.to_s > define_method(m) do > singleton_class = > class << self > self > end > singleton_class.module_eval do > a = [] > define_method m, lambda{ a } > end > send m # recurse into newly defined method > end > end > > arr_meth :arm > end > > ca = C.new; ca.arm << 10 > cb = C.new; cb.arm << 20 > > p ca.arm #-> [10, 20] > p cb.arm #-> [10, 20] > p( ca.arm.eql?( cb.arm ) ) #-> true > > harp:~ > ruby a.rb > [10] > [20] > false > > -a > -- > be kind whenever possible... it is always possible. > - h.h. the 14th dali lama >