module RubyBreaker::RubyTypeUtils

Public Class Methods

subclass_rel?(lhs, rhs) click to toggle source

Checks if lhs is a subclass of rhs

# File lib/rubybreaker/typing/rubytype.rb, line 25
def self.subclass_rel?(lhs, rhs)
  return false unless lhs.kind_of?(Class)
  if lhs == rhs
    return true
  elsif lhs == BasicObject 
    # lhs != rhs and no more to look upward, so quit
    return false
  elsif rhs.instance_of?(Module)
    # lhs != rhs and rhs is a module, so lhs must have a parent module
    # that is a subclass of rhs
    lhs.included_modules.each {|m|
      return true if self.submodule_rel?(m,rhs)
    }
  else
    # then rhs is a class, so just go up as a class
    return self.subclass_rel?(lhs.superclass, rhs)
  end
  return false
end
submodule_rel?(lhs,rhs) click to toggle source

Checks if lhs is a sub-module of rhs

# File lib/rubybreaker/typing/rubytype.rb, line 12
def self.submodule_rel?(lhs,rhs)
  # both lhs and rhs must be modules
  if lhs == rhs 
    return true
  else
    lhs.included_modules.each {|m|
      return true if self.submodule_rel?(m,rhs)
    }
  end 
  return false
end