From: Joel VanderWerf Date: 2005-08-08T05:05:58+09:00 Subject: Re: Adding yet another Array.new form Nikolai Weibull wrote: ... > module Kernel > def returning(value) > yield value > value > end > end ... Why call it #returning and limit its usefulness? The method can be used just as well in assignments: ary = returning [] do ... end or as an argument to a method or proc. Maybe #configure, or #construct? def configure(obj) yield obj obj end def m1 configure ary = [] do ary << 1 ary << 2 end end p m1() # ==> [1, 2] def m2 configure [] do |ary| ary << 1 ary << 2 end end p m2() # ==> [1, 2] I've never used that, but in some cases where there is a parent-child relationship (or a sibling relationship), I've used a #create method, as in the following: def create(*args) klass = args.shift obj = klass.new(*args) # maybe some additional args or setup based on # relation between self and obj yield obj # register obj in self somehow obj end def m3 create Array, 5 do |ary| ary[0] = 1 ary[1] = 2 end end p m3() # ==> [1, 2, nil, nil, nil] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407