Class: RDL::Type::VarargType
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(type) ⇒ VarargType
constructor
A new instance of VarargType.
-
#instantiate(inst) ⇒ Object
Note: no member?, because these can only appear in MethodType, where they’re handled specially.
- #match(other) ⇒ Object
- #to_s ⇒ Object
- #vararg? ⇒ Boolean
Methods inherited from Type
#canonical, leq, #nil_type?, #optional?, #to_contract
Constructor Details
#initialize(type) ⇒ VarargType
Returns a new instance of VarargType.
19 20 21 22 23 24 25 |
# File 'lib/rdl/types/vararg.rb', line 19 def initialize(type) raise "Can't have vararg optional type" if type.is_a? OptionalType raise "Can't have vararg vararg type" if type.is_a? VarargType raise "Can't have optional annotated type" if type.is_a? AnnotatedArgType @type = type super() end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/rdl/types/vararg.rb', line 3 def type @type end |
Class Method Details
.__new__ ⇒ Object
8 |
# File 'lib/rdl/types/vararg.rb', line 8 alias :__new__ :new |
.new(type) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rdl/types/vararg.rb', line 11 def self.new(type) t = @@cache[type] return t if t raise RuntimeError, "Attempt to create vararg type with non-type" unless type.is_a? Type t = VarargType.__new__ type return (@@cache[type] = t) # assignment evaluates to t end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
:nodoc:
35 36 37 38 39 |
# File 'lib/rdl/types/vararg.rb', line 35 def ==(other) # :nodoc: return false if other.nil? other = other.canonical return (other.instance_of? VarargType) && (other.type == @type) end |
#hash ⇒ Object
:nodoc:
56 57 58 |
# File 'lib/rdl/types/vararg.rb', line 56 def hash # :nodoc: return 59 + @type.hash end |
#instantiate(inst) ⇒ Object
Note: no member?, because these can only appear in MethodType, where they’re handled specially
52 53 54 |
# File 'lib/rdl/types/vararg.rb', line 52 def instantiate(inst) return VarargType.new(@type.instantiate(inst)) end |
#match(other) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rdl/types/vararg.rb', line 43 def match(other) other = other.canonical other = other.type if other.instance_of? AnnotatedArgType return true if other.instance_of? WildQuery return (other.instance_of? VarargType) && (@type.match(other.type)) end |
#to_s ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rdl/types/vararg.rb', line 27 def to_s if @type.instance_of? UnionType "*(#{@type.to_s})" else "*#{@type.to_s}" end end |
#vararg? ⇒ Boolean
60 61 62 |
# File 'lib/rdl/types/vararg.rb', line 60 def vararg? return true end |