From: dblack@... Date: 2006-11-17T08:20:12+09:00 Subject: Re: #returning and #tap Hi -- On Fri, 17 Nov 2006, Joel VanderWerf wrote: > Does the following technique seem odd? > > class Foo > attr_accessor :a, :b, :c > def initialize > yield self if block_given? > end > end > > foo = Foo.new do |f| > f.a = 1 > f.b = 2 > f.c = 3 > end > > #then is just a way of using arbitrary classes (or factories) in this way. > Maybe the name should not emphasize the temporal ("then" or "whereupon"); so > maybe "tap" is better, or "configured_using". Part of what's odd to me about #then is that it's not constructor-specific. Once it's defined you could do: x = string.split(',').then do |array| array.map! { something } end Bad example :-) But that's what I meant about not giving it too specific a name, like "post_initialize", since it's not restricted to initialization scenarios. David -- David A. Black | dblack@rubypal.com Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org