Is this pattern current?

R

Robert Dober

Hi list

I just wrote

o = super( *args)
my_init.bind( o ).call( *args )
o

I write code of this patter way too often, I was just thinking that I
really would like to have
module Kernel
def with_value_return_value a_value, &blk
blk.call a_value

end
end
 
R

Robert Dober

Hi list

I just wrote

o = super( *args)
my_init.bind( o ).call( *args )
o

I write code of this patter way too often, I was just thinking that I
really would like to have
module Kernel
def with_value_return_value a_value, &blk
blk.call a_value a_value

end
end


Now of course I can write

with_value_return_value( super(*args) ) do |o|
my_init.bind(o).call(*args)
end

Does someone have a name for this? (mine is a joke, a bad one)

Cheers
Robert
http://ruby-smalltalk.blogspot.com/
 
R

Robert Dober

AFAIK this is called #returning in both facets and activesupport. There
has been a discussion about it a while ago.

http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/70dadf80a5f57e1f/4433b25ea8402832
Very interesting discussion, and the name seems quite ok with me.
As this was more than a year ago I dare adding some reasoning.

What I like most on this idiom is that the local variable is hiding in
the scope, but much more importantly that you can think on a higher
level

o = something
...
...
...
o

just seems low level and I daresay that the final little o, so
important, will be forgotten quite often

returning( something ) do |o|
...
...
...
end

seems so much more robust.

And for what concerns #tap, well impossible to keep a name like that in mind :(.

BTW good to know it's in Facets.

Cheers
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,271
Messages
2,571,354
Members
48,041
Latest member
Oliwen826

Latest Threads

Top