3 self >= a and self <= b
18 ## TODO: i think it doesn't quite work with negative numbers
20 ## keeps a number inside a defined range and wraps it around
21 ## if it steps over the borders. accepts 1-2 integers or a range.
23 ## print n.wrap(4), ', '
26 ## 0, 1, 2, 3, 0, 1, 2, 3, 0,
27 def wrap(max, min = 0)
28 ## if the argument is a range, use it :)
34 ## swap min and max if min is larger than max
39 ## if min is 0, this is the equivalent of a modulo.
40 ## note that ruby's modulo wraps on negative
41 ## numbers :) so there's nothing else to do.
46 ## otherwise, substract min before, and add min after
47 ## the modulo operation to get the correct result.
48 return (self - min) % max + min
52 def second() 1 * self end
53 def minute() 60 * self end
54 def hour() 3600 * self end
55 def day() 86400 * self end
56 def week() 604800 * self end
57 def month() 2629800 * self end
58 def year() 31557600 * self end
69 ### generate the unit methods {{{
75 # 'week' => 3600 * 24 * 7,
76 # 'month' => 3600 * 24 * 30.4375,
77 # 'year' => 3600 * 24 * 365.25,
79 #values.each do |key, val|
80 # puts " def %6s() %10d * self end" % [key, val, key, key]
82 #values.each do |key, val|
83 # puts " alias %8ss %8s" % [key, key]