lib/csl/compatibility.rb in csl-1.0.0.pre23 vs lib/csl/compatibility.rb in csl-1.0.0
- old
+ new
@@ -1,12 +1,30 @@
class Symbol
include Comparable
def <=>(other)
- return unless other.kind_of? Symbol
+ return unless other.kind_of?(Symbol)
to_s <=> other.to_s
end
+
+ def match(pattern)
+ str = to_s
+
+ case pattern
+ when Regexp
+ match_data = pattern.search_region(str, 0, str.bytesize, true)
+ Regexp.last_match = match_data
+ return match_data.full[0] if match_data
+ when String
+ raise TypeError, "type mismatch: String given"
+ else
+ pattern =~ str
+ end
+ end
+
+ alias =~ match
+
end unless Symbol.is_a?(Comparable)
class Module
if RUBY_VERSION < '1.9'
alias const? const_defined?