Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Subclassing Immutable objects (Time
Gavin Kistner
2/10/2005 2:28:00 PM
On Feb 10, 2005, at 6:29 AM, Derek Wyatt wrote:
> I've been trying for a while to subclass Time, but i'm hitting some
> problems. I tried simply overriding the methods in Time itself but
> after about 5 minutes i realized that i needed the old behaviour as
> well, so subclassing seems better. I'm hitting the same problems with
> wrapping the object as well.
In my MutableTime class [1], I wrapped Time, rather than inheriting
from it, and used method_missing to pass functions along to time.
Tiny snippets:
class MutableTime
include Comparable
def initialize( dateString_Seconds_Time_orYear = nil , *dateTimePieces
)
#...
@t=Time.now
end
def method_missing(meth, *args, &block) # :nodoc:
@t.send(meth, *args, &block)
end
def date=(n)
@t+=(n-date)*86400;
end
def +(n)
(d=self.dup).date+=n
d;
end
end
[1]
http://phrogz.net/RubyLibs/rdoc/files/MutableTi...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Subclassing Immutable objects (Time
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