From: Daniel N Date: 2006-07-29T09:56:44+09:00 Subject: Re: What to use binding for? ------=_Part_19954_21453416.1154134600763 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/28/06, Tom Werner wrote: > > 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/Binding.html > > > http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/1d08d0cdb3b53d11 > > > > http://onestepback.org/index.cgi/Tech/Ruby/RubyBindings.rdoc/style/print > > > > 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 #=> # > b = Object.new #=> # > > swap(:a, :b, binding) > > a #=> # > b #=> # > > 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 > > > Thanx guys. This has helped me see how to use binding. Although I'm still not sure when to use it :) ------=_Part_19954_21453416.1154134600763--