[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
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...