aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2014-07-03 14:54:14 -0500
committerJack Nagel2014-07-03 15:00:41 -0500
commitb78308d2d5a8dd26818eba88bb58ee547d6dfdb0 (patch)
tree32b926b90ee329d482206cb737b891ae208fe708 /Library
parent618b894c3e9cf6b0bdb2f46fd258b27d863d1373 (diff)
downloadbrew-b78308d2d5a8dd26818eba88bb58ee547d6dfdb0.tar.bz2
Fix Formula#<=> on trunk Ruby
Arguably this method shouldn't exist and sort_by(&:name) used instead.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb7
-rw-r--r--Library/Homebrew/test/test_formula.rb4
2 files changed, 9 insertions, 2 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 64f329a7e..09dee3cbe 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -301,9 +301,12 @@ class Formula
def hash
name.hash
end
- def <=> b
- name <=> b.name
+
+ def <=>(other)
+ return unless Formula === other
+ name <=> other.name
end
+
def to_s
name
end
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 900d7272c..9a509f3bf 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -139,6 +139,10 @@ class FormulaTests < Homebrew::TestCase
refute_equal TestBall.new, Object.new
end
+ def test_sort_operator
+ assert_nil TestBall.new <=> Object.new
+ end
+
def test_class_naming
assert_equal 'ShellFm', Formulary.class_s('shell.fm')
assert_equal 'Fooxx', Formulary.class_s('foo++')