summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-class-ext/mrblib/module.rb
blob: d35b4cbae0804349e4169051c0dccfdaf514d520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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