From: Patrick Ritchie Date: 2006-02-18T23:51:51+09:00 Subject: Re: define_method fun --Boundary_(ID_j9+nVi7hYNPJM498AUjOxg) Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT Definitely cleaner in my case, thanks for the tip! Cheers! Patrick >Take a look at the Comparable[1] module. It's a much cleaner, simpler >way to accomplish what you're doing. > >[1] http://www.ruby-doc.org/core/classes/Comparable.html > >Gabe > >On 2/17/06, Patrick Ritchie wrote: > > >>Hi All, >> >>I just setup the following in one of my classes, I'll let the code speak >>for itself: >> >>["<", "<=", ">", ">=", "==", "<=>"].each do |op| >> define_method(op) { |comparison| eval "#{self.order} #{op} >>#{comparison.order}" } >>end >> >>Ruby continues to impress me with it's ability to do so much in so few >>amazing readable lines of code. >> >>Are their any good reasons not to declare my op methods this way? Is >>their an even more efficient way to achieve the same effect? >> >>Cheers! >>Patrick >> >> >> >> > > > > --Boundary_(ID_j9+nVi7hYNPJM498AUjOxg)--