Class: Steep::Interface::Shape::MethodOverload
- Defined in:
- lib/steep/interface/shape.rb
Instance Attribute Summary collapse
-
#method_defs ⇒ Object
readonly
Returns the value of attribute method_defs.
-
#method_type ⇒ Object
readonly
Returns the value of attribute method_type.
Instance Method Summary collapse
-
#initialize(method_type, defs) ⇒ MethodOverload
constructor
A new instance of MethodOverload.
- #method_decls(name) ⇒ Object
- #subst(s) ⇒ Object
Constructor Details
#initialize(method_type, defs) ⇒ MethodOverload
Returns a new instance of MethodOverload.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/steep/interface/shape.rb', line 9 def initialize(method_type, defs) @method_type = method_type @method_defs = defs.sort_by do |defn| buf = +"" if loc = defn.type.location buf << loc.buffer.name.to_s buf << ":" buf << loc.start_pos.to_s end buf end @method_defs.uniq! end |
Instance Attribute Details
#method_defs ⇒ Object (readonly)
Returns the value of attribute method_defs.
7 8 9 |
# File 'lib/steep/interface/shape.rb', line 7 def method_defs @method_defs end |
#method_type ⇒ Object (readonly)
Returns the value of attribute method_type.
5 6 7 |
# File 'lib/steep/interface/shape.rb', line 5 def method_type @method_type end |
Instance Method Details
#method_decls(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/steep/interface/shape.rb', line 31 def method_decls(name) method_defs.map do |defn| type_name = defn.implemented_in || defn.defined_in case when name == :new && defn.member.is_a?(RBS::AST::Members::MethodDefinition) && defn.member.name == :initialize method_name = SingletonMethodName.new(type_name: type_name, method_name: name) when name == :new && defn.member.is_a?(RBS::AST::Ruby::Members::DefMember) && defn.member.name == :initialize method_name = SingletonMethodName.new(type_name: type_name, method_name: name) else method_name = case defn.member when RBS::AST::Members::Base if defn.member.kind == :singleton SingletonMethodName.new(type_name: defn.defined_in, method_name: name) else # Call the `self?` method an instance method, because the definition is done with instance method definition, not with singleton method InstanceMethodName.new(type_name: defn.defined_in, method_name: name) end when RBS::AST::Ruby::Members::DefMember, RBS::AST::Ruby::Members::AttributeMember InstanceMethodName.new(type_name: defn.defined_in, method_name: name) end end TypeInference::MethodCall::MethodDecl.new(method_def: defn, method_name: method_name) end end |
#subst(s) ⇒ Object
25 26 27 28 29 |
# File 'lib/steep/interface/shape.rb', line 25 def subst(s) overload = MethodOverload.new(method_type.subst(s), []) overload.method_defs.replace(method_defs) overload end |