Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Is this pattern current?
Robert Dober
11/26/2007 12:01:00 PM
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
--
http://ruby-smalltalk.blo...
---
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
3 Answers
Robert Dober
11/26/2007 12:04:00 PM
0
On Nov 26, 2007 1:00 PM, Robert Dober <robert.dober@gmail.com> wrote:
OOps finger just slipping to the nice Enter key :-(
> 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.blo...
---
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
Sylvain Joyeux
11/26/2007 12:37:00 PM
0
> with_value_return_value( super(*args) ) do |o|
> my_init.bind(o).call(*args)
> end
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/4433b2...
--
Sylvain
Robert Dober
11/26/2007 1:04:00 PM
0
On Nov 26, 2007 1:37 PM, Sylvain Joyeux
<sylvain.joyeux@polytechnique.org> wrote:
> > with_value_return_value( super(*args) ) do |o|
> > my_init.bind(o).call(*args)
> > end
> 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/4433b2...
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
> --
> Sylvain
>
>
--
http://ruby-smalltalk.blo...
---
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Is this pattern current?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password