diff options
| author | Rob <[email protected]> | 2018-12-02 18:38:40 -0500 |
|---|---|---|
| committer | Rob <[email protected]> | 2018-12-02 20:56:47 -0500 |
| commit | e300ac8e3a100aa9538560700050dc3df6cdb09d (patch) | |
| tree | d9074654c2f4e065932590798c31c71ae683d462 /mrbgems/mruby-class-ext/mrblib | |
| parent | 26475d0a7897c25f8632b776014a19c3a6f6ecc2 (diff) | |
| download | mruby-e300ac8e3a100aa9538560700050dc3df6cdb09d.tar.gz mruby-e300ac8e3a100aa9538560700050dc3df6cdb09d.zip | |
Adds Module#< and Module#<=
Diffstat (limited to 'mrbgems/mruby-class-ext/mrblib')
| -rw-r--r-- | mrbgems/mruby-class-ext/mrblib/module.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mrbgems/mruby-class-ext/mrblib/module.rb b/mrbgems/mruby-class-ext/mrblib/module.rb new file mode 100644 index 000000000..d35b4cbae --- /dev/null +++ b/mrbgems/mruby-class-ext/mrblib/module.rb @@ -0,0 +1,39 @@ +class Module + + ## + # call-seq: + # mod < other -> true, false, or nil + # + # Returns true if <i>mod</i> is a subclass of <i>other</i>. 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 "A < B".) + # + def <(other) + raise TypeError, 'compared with non class/module' unless other.is_a?(Module) + if self.equal?(other) + false + else + self <= other + end + end + + ## + # call-seq: + # mod <= other -> true, false, or nil + # + # Returns true if <i>mod</i> is a subclass of <i>other</i> or + # is the same as <i>other</i>. 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 "A < B".) + def <=(other) + raise TypeError, 'compared with non class/module' unless other.is_a?(Module) + if self.ancestors.include?(other) + return true + elsif other.ancestors.include?(self) + return false + end + end + +end |
