From: Tom Werner Date: 2006-07-29T04:42:25+09:00 Subject: Re: What to use binding for? 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