lib/sup/util.rb in sup-0.10.2 vs lib/sup/util.rb in sup-0.11
- old
+ new
@@ -130,10 +130,14 @@
end
## "k combinator"
def returning x; yield x; x; end
+ unless method_defined? :tap
+ def tap; yield self; self; end
+ end
+
## clone of java-style whole-method synchronization
## assumes a @mutex variable
## TODO: clean up, try harder to avoid namespace collisions
def synchronized *methods
methods.each do |meth|
@@ -326,9 +330,16 @@
out
end
def transcode src_encoding=$encoding
Iconv.easy_decode $encoding, src_encoding, self
+ end
+
+ unless method_defined? :ascii_only?
+ def ascii_only?
+ size.times { |i| return false if self[i] & 128 != 0 }
+ return true
+ end
end
end
class Numeric
def clamp min, max