Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: define_method fun
Eric Hodel
2/18/2006 8:25:00 PM
On Feb 17, 2006, at 7:32 PM, 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?
class YourClass
include Comparable
def <=>(other)
self.order <=> other.order
end
end
--
Eric Hodel - drbrain@segment7.net -
http://se...
This implementation is HODEL-HASH-9600 compliant
http://trackmap.rob...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: define_method fun
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