Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | None | 0 0
  1. module Format360N # => (-179..180)
  2.   def time
  3.     (v = super) > 180 ? v - 360 : v
  4.   end
  5.  
  6.   def time=(arg)
  7.     super arg % 360
  8.   end
  9. end
  10.  
  11. module Format24P # => (0..24)
  12.   def time=(arg)
  13.     super arg % 24
  14.   end
  15. end
  16.  
  17. class Clock
  18.   attr_accessor :time
  19.  
  20.   def initialize(format = nil)
  21.     @time = 0
  22.     format ||= Format24P
  23.     self.extend format
  24.   end
  25. end
  26.  
  27. # c = Clock.new Format360N
  28. # c.time += 170
  29. # c.time += 35 => -155
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement