## i'm sure there's pithy comment i could make here about the
## superiority of lisp, but fuck lisp.
def returning x; yield x; x; end
+
+ ## clone of java-style whole-method synchronization
+ ## assumes a @mutex variable
+ def synchronized *meth
+ meth.each do
+ class_eval <<-EOF
+ alias unsynchronized_#{meth} #{meth}
+ def #{meth}(*a, &b)
+ @mutex.synchronize { unsynchronized_#{meth}(*a, &b) }
+ end
+ EOF
+ end
+ end
end
class String
def rest; self[1..-1]; end
def to_boolean_h; Hash[*map { |x| [x, true] }.flatten]; end
-
- ## apparently uniq doesn't use ==. wtf.
- def remove_successive_dupes
- ret = []
- last = nil
- each do |e|
- unless e == last
- ret << e
- last = e
- end
- end
- ret
- end
end
class Time
["month", 12],
["year", nil],
].argfind do |unit, size|
- if diff <= 1
+ if diff.round <= 1
"one #{unit}"
elsif size.nil? || diff.round < size
"#{diff.round} #{unit}s"