Class: RBS::Definition::Method
- Inherits:
-
Object
- Object
- RBS::Definition::Method
- Defined in:
- lib/rbs/definition.rb
Defined Under Namespace
Classes: TypeDef
Instance Attribute Summary collapse
-
#accessibility ⇒ Object
readonly
Returns the value of attribute accessibility.
-
#alias_of ⇒ Object
readonly
Returns the value of attribute alias_of.
-
#defs ⇒ Object
readonly
Returns the value of attribute defs.
-
#extra_annotations ⇒ Object
readonly
Returns the value of attribute extra_annotations.
-
#super_method ⇒ Object
readonly
Returns the value of attribute super_method.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #annotations ⇒ Object
- #comments ⇒ Object
- #defined_in ⇒ Object
- #hash ⇒ Object
- #implemented_in ⇒ Object
-
#initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:) ⇒ Method
constructor
A new instance of Method.
- #map_method_type(&block) ⇒ Object
- #map_type(&block) ⇒ Object
- #map_type_bound(&block) ⇒ Object
- #members ⇒ Object
- #method_types ⇒ Object
- #private? ⇒ Boolean
- #public? ⇒ Boolean
- #sub(s) ⇒ Object
- #update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations) ⇒ Object
Constructor Details
#initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:) ⇒ Method
Returns a new instance of Method.
83 84 85 86 87 88 89 |
# File 'lib/rbs/definition.rb', line 83 def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:) @super_method = super_method @defs = defs @accessibility = accessibility @extra_annotations = [] @alias_of = alias_of end |
Instance Attribute Details
#accessibility ⇒ Object (readonly)
Returns the value of attribute accessibility.
79 80 81 |
# File 'lib/rbs/definition.rb', line 79 def accessibility @accessibility end |
#alias_of ⇒ Object (readonly)
Returns the value of attribute alias_of.
81 82 83 |
# File 'lib/rbs/definition.rb', line 81 def alias_of @alias_of end |
#defs ⇒ Object (readonly)
Returns the value of attribute defs.
78 79 80 |
# File 'lib/rbs/definition.rb', line 78 def defs @defs end |
#extra_annotations ⇒ Object (readonly)
Returns the value of attribute extra_annotations.
80 81 82 |
# File 'lib/rbs/definition.rb', line 80 def extra_annotations @extra_annotations end |
#super_method ⇒ Object (readonly)
Returns the value of attribute super_method.
77 78 79 |
# File 'lib/rbs/definition.rb', line 77 def super_method @super_method end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
91 92 93 94 95 96 97 98 |
# File 'lib/rbs/definition.rb', line 91 def ==(other) other.is_a?(Method) && other.super_method == super_method && other.defs == defs && other.accessibility == accessibility && other.annotations == annotations && other.alias_of == alias_of end |
#annotations ⇒ Object
128 129 130 |
# File 'lib/rbs/definition.rb', line 128 def annotations @annotations ||= defs.flat_map {|d| d.member_annotations } end |
#comments ⇒ Object
124 125 126 |
# File 'lib/rbs/definition.rb', line 124 def comments @comments ||= defs.map(&:comment).compact.uniq end |
#defined_in ⇒ Object
106 107 108 109 110 111 |
# File 'lib/rbs/definition.rb', line 106 def defined_in @defined_in ||= begin last_def = defs.last or raise last_def.defined_in end end |
#hash ⇒ Object
102 103 104 |
# File 'lib/rbs/definition.rb', line 102 def hash self.class.hash ^ super_method.hash ^ defs.hash ^ accessibility.hash ^ annotations.hash ^ alias_of.hash end |
#implemented_in ⇒ Object
113 114 115 116 117 118 |
# File 'lib/rbs/definition.rb', line 113 def implemented_in @implemented_in ||= begin last_def = defs.last or raise last_def.implemented_in end end |
#map_method_type(&block) ⇒ Object
171 172 173 174 175 176 177 178 |
# File 'lib/rbs/definition.rb', line 171 def map_method_type(&block) self.class.new( super_method: super_method, defs: defs.map {|defn| defn.update(type: yield(defn.type)) }, accessibility: @accessibility, alias_of: alias_of ) end |
#map_type(&block) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/rbs/definition.rb', line 153 def map_type(&block) self.class.new( super_method: super_method&.map_type(&block), defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) }, accessibility: @accessibility, alias_of: alias_of ) end |
#map_type_bound(&block) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/rbs/definition.rb', line 162 def map_type_bound(&block) self.class.new( super_method: super_method&.map_type_bound(&block), defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) }, accessibility: @accessibility, alias_of: alias_of ) end |
#members ⇒ Object
132 133 134 |
# File 'lib/rbs/definition.rb', line 132 def members @members ||= defs.map(&:member).uniq end |
#method_types ⇒ Object
120 121 122 |
# File 'lib/rbs/definition.rb', line 120 def method_types @method_types ||= defs.map(&:type) end |
#private? ⇒ Boolean
140 141 142 |
# File 'lib/rbs/definition.rb', line 140 def private? @accessibility == :private end |
#public? ⇒ Boolean
136 137 138 |
# File 'lib/rbs/definition.rb', line 136 def public? @accessibility == :public end |
#sub(s) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/rbs/definition.rb', line 144 def sub(s) self.class.new( super_method: super_method&.sub(s), defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) }, accessibility: @accessibility, alias_of: alias_of ) end |
#update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/rbs/definition.rb', line 180 def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations) self.class.new( super_method: super_method, defs: defs, accessibility: accessibility, alias_of: alias_of, annotations: annotations ) end |