We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52dc8b0 commit 5ea2864Copy full SHA for 5ea2864
corelib/kernel.rb
@@ -20,6 +20,16 @@ def ===(other)
20
`#{self} == other`
21
end
22
23
+ def <=>(other)
24
+ %x{
25
+ if (#{self == other}) {
26
+ return 0;
27
+ }
28
+
29
+ return nil;
30
31
+ end
32
33
def method(name)
34
%x{
35
var recv = #{self},
spec/rubyspec/core/kernel/comparison_spec.rb
@@ -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
9
10
+ it "returns nil if self is not == to the argument" do
11
12
+ (obj.<=>(3.14)).should be_nil
13
14
15
+end
0 commit comments