From: Jean-Hugues ROBERT Date: 2004-05-02T03:02:00+09:00 Subject: Why no Proc##[]=() ? Why no Proc##replace() ? Hi, Looking at lvalues in Ruby I learned a lot. I thought Proc instances could be turned into lvalues too, so I tried: class Proc def []=(*args) self[*args] end end pp = proc { |*x| @val = x[0] unless x.empty? ; @val } pp[] = 1 # => 1 p pp[] # => 1 Ruby's cool, no doubts. Is this worth a RCR ? Then I tried to rebuilt my version of a Pointer class at http://www.c2.com/cgi/wiki?SinisterSchemeSampleInRuby with what I had learnt. class Pointer < Proc def initialize( &block ) ref( &block) end def ref( &block ) lvalue = block.call() tmp = eval( "proc { |*x| #{lvalue} = x[0] unless x.empty? ; #{lvalue} }", block) self.replace tmp end def to_s() self[].to_s() end def inspect() "#{self[].inspect()}" end end That would be considerably simpler, the body makes 8 lines versus 16. But it does not work, there is no Proc##replace() Yours, Jean-Hugues ------------------------------------------------------------------------ Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17