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
e6bad676
Commit
e6bad676
authored
Dec 04, 2018
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new methods `Module#{>,>=,<=>}`; ref #4174
parent
d5d9cc8b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
mrbgems/mruby-class-ext/mrblib/module.rb
mrbgems/mruby-class-ext/mrblib/module.rb
+51
-0
No files found.
mrbgems/mruby-class-ext/mrblib/module.rb
View file @
e6bad676
...
@@ -35,4 +35,55 @@ class Module
...
@@ -35,4 +35,55 @@ class Module
end
end
end
end
##
# call-seq:
# mod > other -> true, false, or nil
#
# Returns true if `mod` is an ancestor of `other`. Returns
# <code>nil</code> if there's no relationship between the two.
# (Think of the relationship in terms of the class definition:
# "class A < B" implies "B > A".)
#
def
>
(
other
)
if
self
.
equal?
(
other
)
false
else
self
>=
other
end
end
##
# call-seq:
# mod >= other -> true, false, or nil
#
# Returns true if `mod` is an ancestor of `other`, or the
# two modules are the same. Returns
# <code>nil</code> if there's no relationship between the two.
# (Think of the relationship in terms of the class definition:
# "class A < B" implies "B > A".)
#
def
>
=
(
other
)
raise
TypeError
,
'compared with non class/module'
unless
other
.
is_a?
(
Module
)
return
other
<
self
end
##
# call-seq:
# module <=> other_module -> -1, 0, +1, or nil
#
# Comparison---Returns -1, 0, +1 or nil depending on whether `module`
# includes `other_module`, they are the same, or if `module` is included by
# `other_module`.
#
# Returns `nil` if `module` has no relationship with `other_module`, if
# `other_module` is not a module, or if the two values are incomparable.
#
def
<
=>
(
other
)
return
0
if
self
.
equal?
(
other
)
return
nil
unless
other
.
is_a?
(
Module
)
cmp
=
self
<
other
return
-
1
if
cmp
return
1
unless
cmp
.
nil?
return
nil
end
end
end
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