Class: Steep::AST::Builtin::Type
Instance Attribute Summary collapse
-
#arity ⇒ Object
readonly
Returns the value of attribute arity.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
Instance Method Summary collapse
-
#initialize(module_name, arity: 0) ⇒ Type
constructor
A new instance of Type.
- #instance_type(*args, fill_untyped: false) ⇒ Object
- #instance_type?(type, args: nil) ⇒ Boolean
- #module_type ⇒ Object
- #module_type?(type) ⇒ Boolean
Constructor Details
#initialize(module_name, arity: 0) ⇒ Type
Returns a new instance of Type.
8 9 10 11 |
# File 'lib/steep/ast/builtin.rb', line 8 def initialize(module_name, arity: 0) @module_name = RBS::TypeName.parse(module_name) @arity = arity end |
Instance Attribute Details
#arity ⇒ Object (readonly)
Returns the value of attribute arity.
6 7 8 |
# File 'lib/steep/ast/builtin.rb', line 6 def arity @arity end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
5 6 7 |
# File 'lib/steep/ast/builtin.rb', line 5 def module_name @module_name end |
Instance Method Details
#instance_type(*args, fill_untyped: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/steep/ast/builtin.rb', line 13 def instance_type(*args, fill_untyped: false) if fill_untyped (arity - args.size).times do args << Builtin.any_type end end arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}" Types::Name::Instance.new(name: module_name, args: args) end |
#instance_type?(type, args: nil) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/steep/ast/builtin.rb', line 28 def instance_type?(type, args: nil) if type.is_a?(Types::Name::Instance) if args arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}" if type.name == module_name && type.args == args type end else if type.name == module_name && type.args.size == arity type end end end end |