Skip to content

Commit

Permalink
Implement Kernel#<=> with specs (fixes #361)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 10, 2013
1 parent 52dc8b0 commit 5ea2864
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions corelib/kernel.rb
Expand Up @@ -20,6 +20,16 @@ def ===(other)
`#{self} == other`
end

def <=>(other)
%x{
if (#{self == other}) {
return 0;
}
return nil;
}
end

def method(name)
%x{
var recv = #{self},
Expand Down
15 changes: 15 additions & 0 deletions spec/rubyspec/core/kernel/comparison_spec.rb
@@ -0,0 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.9" do
describe "Kernel#<=>" do
it "returns 0 if self" do
obj = Object.new
(obj.<=>(obj)).should == 0
end

it "returns nil if self is not == to the argument" do
obj = Object.new
(obj.<=>(3.14)).should be_nil
end
end
end

0 comments on commit 5ea2864

Please sign in to comment.