From: Mike Harris Date: 2006-07-21T09:14:45+09:00 Subject: Re: Using .each with constructors transfire@gmail.com wrote: >Robert Dober wrote: > > > >>I prefer to write >> >>class Class >> def *(num) >> a = [] >> num.times do >> a << new >> end >> a >> end >>end >> >> > >Hmm...It's too bad that #times below returns 3. It be pretty neat if it >acted like #map in this respect instead. > > 3.times { Object.new } > > The solution i use to this is (1..3).map { Object.new }. It's elegant/concise enough for me >Also > > ([lambda{Object.new}]*3).collect{|c| c.call } > >and Robert's solution lead me too: > > class Proc > def *(i) > a = [] > i.times{ a << call } > a > end > end > > lambda{ Object.new } * 3 > >Which is pretty versitle. Unforunately I already have Proc#* tied up >with function composition. > >T. > > > > >