Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: creating a ! method
Gavin Kistner
6/13/2005 10:15:00 PM
One potential way to accomplish this is what I did in my MutableTime class[1]. Create a new class that has an internal Time instance variable and -- when you want to 'round' your time -- replace this instance variable with the new Time instance. Judicious use of #method_missing allows your class to pass off any methods it doesn't understand to the time instance.
[1]
http://phrogz.net/RubyLibs/rdoc/files/MutableTi...
________________________________
From: Jamis Buck [mailto:jamis@37signals.com]
Sent: Mon 6/13/2005 11:55 AM
To: ruby-talk ML
Subject: Re: creating a ! method
On Jun 13, 2005, at 11:51 AM, Kurt V. Hindenburg wrote:
> Hello,
> I have this code. It works fine but I would like to use
> round_to_interval!.
> I could not figure out how to code that. Any suggestions?
>
> class Time
> def round_to_interval!
> # how?
> end
>
> def round_to_interval
> self - (self.min % 10) * 60
> end
> end
>
>
Time objects are immutable (like numbers, symbols, etc.), so you
cannot alter them directly.
- Jamis
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: creating a ! method
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