nowvalue.rb 629 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Nowvalue is a mix in module module used to model values that have a current
  2. # value "now"
  3. # The class this is miked in must respond_to? :make(value) and :clamp(value).
  4. module Nowvalue
  5. attr_reader :now
  6. def initalize(n)
  7. @now = n
  8. end
  9. def now=(value)
  10. @now = clamp(value)
  11. end
  12. def +(value)
  13. return make(@now + value)
  14. end
  15. def *(value)
  16. return make(@now * value)
  17. end
  18. def -(value)
  19. return make(@now - value)
  20. end
  21. def /(value)
  22. return make(@now / value)
  23. end
  24. def **(value)
  25. return make(@now ** value)
  26. end
  27. def <=>(value)
  28. return @now <=> value
  29. end
  30. end