Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
counter object / ++ lookalike
John-Mason P. Shackelford
4/1/2005 8:21:00 PM
Am I missing a part of the standard library that already does something
like the following?
class Counter < DelegateClass(Fixnum)
def initialize
__setobj__(0)
end
def inc
__setobj__(__getobj__.next)
self
end
end
x = Counter.new # x == 0
x.inc # x == 1
x.inc.inc.inc # x == 4
Thanks,
John-Mason Shackelford
Software Developer
Pearson Educational Measurement
2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
john-mason.shackelford@pearson.com
http://pearsonedmeasu...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
counter object / ++ lookalike
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