From: Simon Strandgaard Date: 2004-05-01T21:17:28+09:00 Subject: Re: def [](v) xx; return yy; end # returned value is ignored !? Jean-Hugues ROBERT wrote: > Ruby is cool, a lvalue can be a *method call*. > So when I say "lvalue" I mean Ruby's ones, not the subset that some > other languages provide. > > I believe my version of Pointer works with any Ruby valid lvalue: > a = [1,2,3] > ptr = Pointer.new{ "a[2]"} > ptr[] = 4 > p a # => [1,2,4] > See it at end of page http://www.c2.com/cgi/wiki?SinisterSchemeSampleInRuby > I have made iterator package, which does the same, plus a few other goodies (continuation-iterator), see http://raa.ruby-lang.org/list.rhtml?name=iterator Only difference I see, is that you use a String, where I use a reference. Any advantages in using a String over a reference ? irb(main):001:0> require 'iterator' => true irb(main):002:0> a = [1,2,3] => [1, 2, 3] irb(main):003:0> ptr = a.create_iterator => # irb(main):004:0> ptr.next(2) => # irb(main):005:0> ptr.current = 4 => 4 irb(main):006:0> p a [1, 2, 4] => nil -- Simon Strandgaard