From: Sergey Volkov Date: 2006-05-11T14:37:31+09:00 Subject: plz help with binding Ruby guru, please help: I'm creating variable-less storage, wich works fine: # def arr_fn() ; arr=[] ; lambda{ arr } ; end fa = arr_fn ; fa[] << 10 fb = arr_fn ; fb[] << 20 p fa[] #=> [10] p fb[] #=> [20] # note that fa, fb have different binding for local arr - as expected Now I'm trying to create instance-var-less storage: # class C def self.arr_meth( sym ) arr = [] define_method sym.to_sym, lambda{ arr } 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 # Why ca.arm, cb.arm share same local variable? Is it bug or feature? thanks brs Sergey -- Posted via http://www.ruby-forum.com/.