counter object / ++ lookalike

  • Thread starter John-Mason P. Shackelford
  • Start date
J

John-Mason P. Shackelford

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
(e-mail address removed)
http://pearsonedmeasurement.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top