From: Joel VanderWerf Date: 2006-11-17T07:38:11+09:00 Subject: Re: #returning and #tap dblack@wobblini.net wrote: > Hi -- > > On Fri, 17 Nov 2006, Joel VanderWerf wrote: > >> dblack@wobblini.net wrote: >>> Hi -- >>> >>> On Fri, 17 Nov 2006, Joel VanderWerf wrote: >>> >>>> Coming full circle around the golf course... This last one above is >>>> what lead me to prefer #then (== #tap) in the first place: >>>> >>>> def foo >>>> @foo ||= Foo.new.then do |f| >>>> f.bar = "bar" >>>> end >>>> end >>>> >>>> Also, #then avoids the scoping nastiness of #instance_eval. >>> >>> I'm not getting the semantics of "then". Do you mean "then" as in, "I >>> took off my coat and then sat down", as opposed to then in if/then? >> >> Yes. Not much better than #tap, is it? Any ideas...? "and_then"? > > "whereupon" :-) I guess it's hard to find a name that's general > enough (as opposed to, say, "post_initialize") but also expressive > enough. It does seem a slightly odd technique to me, in any case -- > sort of like saying "Now I'm going to do this: this" instead of just > going to a new line and saying: "this". I'm not sure how much of the > oddness I feel is the technique as opposed to the naming issue. 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". Btw, I don't think I've ever used #then in more than 5 or 6 places. Usually, I just try to define classes like Foo above. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407