Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
72fe1922
Commit
72fe1922
authored
Mar 21, 2014
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix behavior of Comparable methods
when <=> return nil
parent
2c44f96e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
mrblib/compar.rb
mrblib/compar.rb
+4
-4
test/t/comparable.rb
test/t/comparable.rb
+20
-12
No files found.
mrblib/compar.rb
View file @
72fe1922
...
...
@@ -13,7 +13,7 @@ module Comparable
def
<
other
cmp
=
self
<=>
other
if
cmp
.
nil?
false
raise
ArgumentError
,
"comparison of
#{
self
.
class
}
with
#{
other
.
class
}
failed"
elsif
cmp
<
0
true
else
...
...
@@ -30,7 +30,7 @@ module Comparable
def
<
=
other
cmp
=
self
<=>
other
if
cmp
.
nil?
false
raise
ArgumentError
,
"comparison of
#{
self
.
class
}
with
#{
other
.
class
}
failed"
elsif
cmp
<=
0
true
else
...
...
@@ -62,7 +62,7 @@ module Comparable
def
>
other
cmp
=
self
<=>
other
if
cmp
.
nil?
false
raise
ArgumentError
,
"comparison of
#{
self
.
class
}
with
#{
other
.
class
}
failed"
elsif
cmp
>
0
true
else
...
...
@@ -79,7 +79,7 @@ module Comparable
def
>
=
other
cmp
=
self
<=>
other
if
cmp
.
nil?
false
raise
ArgumentError
,
"comparison of
#{
self
.
class
}
with
#{
other
.
class
}
failed"
elsif
cmp
>=
0
true
else
...
...
test/t/comparable.rb
View file @
72fe1922
...
...
@@ -3,22 +3,26 @@ assert('Comparable#<', '15.3.3.2.1') do
class
Foo
include
Comparable
def
<
=>
(
x
)
0
x
end
end
assert_false
(
Foo
.
new
<
Foo
.
new
)
assert_false
(
Foo
.
new
<
0
)
assert_false
(
Foo
.
new
<
1
)
assert_true
(
Foo
.
new
<
-
1
)
assert_raise
(
ArgumentError
){
Foo
.
new
<
nil
}
end
assert
(
'Comparable#<='
,
'15.3.3.2.2'
)
do
class
Foo
include
Comparable
def
<
=>
(
x
)
0
x
end
end
assert_true
(
Foo
.
new
<=
Foo
.
new
)
assert_true
(
Foo
.
new
<=
0
)
assert_false
(
Foo
.
new
<=
1
)
assert_true
(
Foo
.
new
<=
-
1
)
assert_raise
(
ArgumentError
){
Foo
.
new
<=
nil
}
end
assert
(
'Comparable#=='
,
'15.3.3.2.3'
)
do
...
...
@@ -36,22 +40,26 @@ assert('Comparable#>', '15.3.3.2.4') do
class
Foo
include
Comparable
def
<
=>
(
x
)
0
x
end
end
assert_false
(
Foo
.
new
>
Foo
.
new
)
assert_false
(
Foo
.
new
>
0
)
assert_true
(
Foo
.
new
>
1
)
assert_false
(
Foo
.
new
>
-
1
)
assert_raise
(
ArgumentError
){
Foo
.
new
>
nil
}
end
assert
(
'Comparable#>='
,
'15.3.3.2.5'
)
do
class
Foo
include
Comparable
def
<
=>
(
x
)
0
x
end
end
assert_true
(
Foo
.
new
>=
Foo
.
new
)
assert_true
(
Foo
.
new
>=
0
)
assert_true
(
Foo
.
new
>=
1
)
assert_false
(
Foo
.
new
>=
-
1
)
assert_raise
(
ArgumentError
){
Foo
.
new
>=
nil
}
end
assert
(
'Comparable#between?'
,
'15.3.3.2.6'
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment