backports 1.6.7 → 1.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 6
4
- :patch: 7
4
+ :patch: 8
@@ -4,17 +4,34 @@ class Symbol
4
4
  Proc.new { |*args| args.shift.__send__(self, *args) }
5
5
  end unless :to_proc.respond_to?(:to_proc)
6
6
 
7
- [ [%w(<=> casecmp), {:before => "return nil unless args.first.is_a? Symbol" }],
8
- [%w(capitalize downcase next succ swapcase upcase), {:after => ".to_s"}],
7
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
8
+ [ [%w(capitalize downcase next succ swapcase upcase), {:after => ".to_sym"}],
9
9
  [%w(=~ [] empty? length match size), {}]
10
10
  ].each { |methods, options| methods.each do |method|
11
11
  module_eval <<-end_eval
12
12
  def #{method}(*args)
13
- #{options[:before]}
14
13
  to_s.#{method}(*args)#{options[:after]}
15
14
  end unless method_defined? :#{method}
16
15
  end_eval
17
16
  end }
18
17
 
19
- include Comparable unless ancestors.include? Comparable
18
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
19
+ def <=>(with)
20
+ return nil unless with.is_a? Symbol
21
+ to_s <=> with.to_s
22
+ end unless method_defined? :"<=>"
23
+
24
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
25
+ def casecmp(with)
26
+ return nil unless with.is_a? Symbol
27
+ to_s.casecmp(with.to_s)
28
+ end unless method_defined? :casecmp
29
+
30
+ # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
31
+ unless ancestors.include? Comparable
32
+ alias_method :dont_override_equal_please, :==
33
+ include Comparable
34
+ alias_method :==, :dont_override_equal_please
35
+ end
36
+
20
37
  end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class SymbolTest < Test::Unit::TestCase
4
+ context "Symbol" do
5
+ context "comparison" do
6
+ should "work as expected" do
7
+ assert_equal false, :abc == :def
8
+ assert_equal true, :abc == :abc
9
+ assert_equal false, :abc == "abc"
10
+ assert_equal false, :abc > :def
11
+ assert_equal true, :abc < :def
12
+ assert_raise(ArgumentError) {:abc < "def"}
13
+ end
14
+ end
15
+
16
+ context "string ops" do
17
+ should "work as expected" do
18
+ assert_equal :HELLO, :hello.upcase
19
+ assert_equal 5, :hello.length
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -60,6 +60,7 @@ files:
60
60
  - test/object_test.rb
61
61
  - test/regexp_test.rb
62
62
  - test/string_test.rb
63
+ - test/symbol_test.rb
63
64
  - test/test_helper.rb
64
65
  has_rdoc: true
65
66
  homepage: http://github.com/marcandre/backports
@@ -105,4 +106,5 @@ test_files:
105
106
  - test/object_test.rb
106
107
  - test/regexp_test.rb
107
108
  - test/string_test.rb
109
+ - test/symbol_test.rb
108
110
  - test/test_helper.rb