Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: What to use binding for?
Gene Tani
7/28/2006 5:38:00 AM
Daniel N wrote:
> Hi everyone,
>
> There was a post a couple of days ago that included a call to binding
>
> I was interested in this and went to look up the binding docs. All good, it
> seems simple enough, but I can't think of how to use it.
>
> Could anyone provide a simple explaination/code of an example of how it
> might be used.
>
Google say:
http://extensions.rubyforge.org/rdoc/classes/Bi...
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/1d08d0...
http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc/s...
1 Answer
Tom Werner
7/28/2006 7:42:00 PM
0
Gene Tani wrote:
> Daniel N wrote:
>
>> Hi everyone,
>>
>> There was a post a couple of days ago that included a call to binding
>>
>> I was interested in this and went to look up the binding docs. All good, it
>> seems simple enough, but I can't think of how to use it.
>>
>> Could anyone provide a simple explaination/code of an example of how it
>> might be used.
>>
>>
> Google say:
>
>
http://extensions.rubyforge.org/rdoc/classes/Bi...
>
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/1d08d0...
>
>
http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc/s...
>
Looking at Jim Weirich's article on writing a local variable swap method
using binding, I couldn't help but think that the following would reduce
code size, complexity, and call keystrokes in the final embodiment of
the method:
def swap(a, b, bind)
eval "#{a}, #{b} = #{b}, #{a}", bind
end
a = Object.new #=> #<Object:0x2c64540>
b = Object.new #=> #<Object:0x2c617c8>
swap(:a, :b, binding)
a #=> #<Object:0x2c617c8>
b #=> #<Object:0x2c64540>
Not that I have any delusions about this pedagogical method having any
relevance in the real world, but there it is just the same.
Tom
--
Tom Werner
Helmets to Hardhats
Software Developer
tom@helmetstohardhats.org
www.helmetstohardhats.org
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: What to use binding for?
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