lib/sup/util.rb in sup-0.0.6 vs lib/sup/util.rb in sup-0.0.7

- old
+ new

@@ -41,10 +41,23 @@ ## with(expensive_operation) { |x| log "got #{x}" } ## ## 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 camel_to_hyphy self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase @@ -174,22 +187,9 @@ def to_h; Hash[*flatten]; end 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 def to_indexable_s sprintf "%012d", self