From: Hugh Sasse Staff Elec Eng Date: 2000-08-07T16:25:37+01:00 Subject: [ruby-talk:04331] Re: TABWTDI and Hash.new([]) Hmm. that took me a while to figure out! I think that is good. Hugh. hgs@dmu.ac.uk On Mon, 7 Aug 2000, ts wrote: > >>>>> "H" == Hugh Sasse Staff Elec Eng writes: > > H> I agree with those sentiments as well. I wonder if this would be worth > H> extending more gnerally, so user-created classes can use it? > > Something like this ? > > pigeon% cat b.rb > #!/usr/bin/ruby > class A > def initialize > @a = [] > @obj = if iterator? > Proc.new > else > nil > end > end > def add(*args) > @a += if @obj && args.size == 0 > @obj.call > else > args > end > end > end > > a = A.new {[1, 2] + 1} > a.add > p a > a.add [12, 24] > p a > > pigeon% b.rb > #> > #> > pigeon% > > > Guy Decoux > >