lib/backports/symbol.rb in backports-1.6.7 vs lib/backports/symbol.rb in backports-1.6.8
- old
+ new
@@ -2,19 +2,36 @@
# Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end unless :to_proc.respond_to?(:to_proc)
- [ [%w(<=> casecmp), {:before => "return nil unless args.first.is_a? Symbol" }],
- [%w(capitalize downcase next succ swapcase upcase), {:after => ".to_s"}],
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
+ [ [%w(capitalize downcase next succ swapcase upcase), {:after => ".to_sym"}],
[%w(=~ [] empty? length match size), {}]
].each { |methods, options| methods.each do |method|
module_eval <<-end_eval
def #{method}(*args)
- #{options[:before]}
to_s.#{method}(*args)#{options[:after]}
end unless method_defined? :#{method}
end_eval
end }
- include Comparable unless ancestors.include? Comparable
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
+ def <=>(with)
+ return nil unless with.is_a? Symbol
+ to_s <=> with.to_s
+ end unless method_defined? :"<=>"
+
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
+ def casecmp(with)
+ return nil unless with.is_a? Symbol
+ to_s.casecmp(with.to_s)
+ end unless method_defined? :casecmp
+
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
+ unless ancestors.include? Comparable
+ alias_method :dont_override_equal_please, :==
+ include Comparable
+ alias_method :==, :dont_override_equal_please
+ end
+
end