Class: RDL::Type::VarType
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=(other) ⇒ Object
an uninstantiated variable is only comparable to itself.
- #==(other) ⇒ Object (also: #eql?)
- #copy ⇒ Object
-
#hash ⇒ Object
:nodoc:.
-
#initialize(name) ⇒ VarType
constructor
A new instance of VarType.
- #instantiate(inst) ⇒ Object
- #match(other) ⇒ Object
- #member?(obj, vars_wild: false) ⇒ Boolean
-
#to_s ⇒ Object
:nodoc:.
- #widen ⇒ Object
Methods included from RDL::Type
Constructor Details
#initialize(name) ⇒ VarType
Returns a new instance of VarType.
19 20 21 |
# File 'lib/rdl/types/var.rb', line 19 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/rdl/types/var.rb', line 3 def name @name end |
Class Method Details
.__new__ ⇒ Object
8 |
# File 'lib/rdl/types/var.rb', line 8 alias :__new__ :new |
.new(name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rdl/types/var.rb', line 11 def self.new(name) name = name.to_s.to_sym t = @@cache[name] return t if t t = self.__new__ name return (@@cache[name] = t) # assignment evaluates to t end |
Instance Method Details
#<=(other) ⇒ Object
an uninstantiated variable is only comparable to itself
36 37 38 |
# File 'lib/rdl/types/var.rb', line 36 def <=(other) return Type.leq(self, other) end |
#==(other) ⇒ Object Also known as: eql?
27 28 29 30 31 |
# File 'lib/rdl/types/var.rb', line 27 def ==(other) return false if other.nil? other = other.canonical return (other.instance_of? self.class) && (other.name.to_s == @name.to_s) end |
#copy ⇒ Object
66 67 68 |
# File 'lib/rdl/types/var.rb', line 66 def copy self end |
#hash ⇒ Object
:nodoc:
47 48 49 |
# File 'lib/rdl/types/var.rb', line 47 def hash # :nodoc: return @name.to_s.hash end |
#instantiate(inst) ⇒ Object
56 57 58 59 |
# File 'lib/rdl/types/var.rb', line 56 def instantiate(inst) return inst[@name] if inst[@name] return self end |
#match(other) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rdl/types/var.rb', line 40 def match(other) other = other.canonical other = other.type if other.instance_of? AnnotatedArgType return true if other.instance_of? WildQuery return self == other end |
#member?(obj, vars_wild: false) ⇒ Boolean
51 52 53 54 |
# File 'lib/rdl/types/var.rb', line 51 def member?(obj, vars_wild: false) return true if vars_wild raise TypeError, "Unbound type variable #{@name}" end |
#to_s ⇒ Object
:nodoc:
23 24 25 |
# File 'lib/rdl/types/var.rb', line 23 def to_s # :nodoc: return @name.to_s end |
#widen ⇒ Object
61 62 63 64 |
# File 'lib/rdl/types/var.rb', line 61 def widen return inst[@name] if inst[@name] return self end |