Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Format360N # => (-179..180)
- def time
- (v = super) > 180 ? v - 360 : v
- end
- def time=(arg)
- super arg % 360
- end
- end
- module Format24P # => (0..24)
- def time=(arg)
- super arg % 24
- end
- end
- class Clock
- attr_accessor :time
- def initialize(format = nil)
- @time = 0
- format ||= Format24P
- self.extend format
- end
- end
- # c = Clock.new Format360N
- # c.time += 170
- # c.time += 35 => -155
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement