Skip to content

Commit 5ea2864

Browse files
committed
Implement Kernel#<=> with specs (fixes #361)
1 parent 52dc8b0 commit 5ea2864

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

corelib/kernel.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def ===(other)
2020
`#{self} == other`
2121
end
2222

23+
def <=>(other)
24+
%x{
25+
if (#{self == other}) {
26+
return 0;
27+
}
28+
29+
return nil;
30+
}
31+
end
32+
2333
def method(name)
2434
%x{
2535
var recv = #{self},
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require File.expand_path('../../../spec_helper', __FILE__)
2+
3+
ruby_version_is "1.9" do
4+
describe "Kernel#<=>" do
5+
it "returns 0 if self" do
6+
obj = Object.new
7+
(obj.<=>(obj)).should == 0
8+
end
9+
10+
it "returns nil if self is not == to the argument" do
11+
obj = Object.new
12+
(obj.<=>(3.14)).should be_nil
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)