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_member ⇒ Object
readonly
Returns the value of attribute alias_member.
-
#alias_of ⇒ Object
readonly
Returns the value of attribute alias_of.
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#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?)
- #comments ⇒ Object
- #defined_in ⇒ Object
- #hash ⇒ Object
- #implemented_in ⇒ Object
-
#initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil) ⇒ 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, alias_member: self.alias_member) ⇒ Object
Constructor Details
#initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil) ⇒ Method
Returns a new instance of Method.
102 103 104 105 106 107 108 109 110 |
# File 'lib/rbs/definition.rb', line 102 def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil) @super_method = super_method @defs = defs @accessibility = accessibility @extra_annotations = [] @annotations = [] @alias_of = alias_of @alias_member = alias_member end |
Instance Attribute Details
#accessibility ⇒ Object (readonly)
Returns the value of attribute accessibility.
96 97 98 |
# File 'lib/rbs/definition.rb', line 96 def accessibility @accessibility end |
#alias_member ⇒ Object (readonly)
Returns the value of attribute alias_member.
100 101 102 |
# File 'lib/rbs/definition.rb', line 100 def alias_member @alias_member end |
#alias_of ⇒ Object (readonly)
Returns the value of attribute alias_of.
99 100 101 |
# File 'lib/rbs/definition.rb', line 99 def alias_of @alias_of end |
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
98 99 100 |
# File 'lib/rbs/definition.rb', line 98 def annotations @annotations end |
#defs ⇒ Object (readonly)
Returns the value of attribute defs.
95 96 97 |
# File 'lib/rbs/definition.rb', line 95 def defs @defs end |
#extra_annotations ⇒ Object (readonly)
Returns the value of attribute extra_annotations.
97 98 99 |
# File 'lib/rbs/definition.rb', line 97 def extra_annotations @extra_annotations end |
#super_method ⇒ Object (readonly)
Returns the value of attribute super_method.
94 95 96 |
# File 'lib/rbs/definition.rb', line 94 def super_method @super_method end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
112 113 114 115 116 117 118 119 120 |
# File 'lib/rbs/definition.rb', line 112 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 && other.alias_member == alias_member end |
#comments ⇒ Object
146 147 148 |
# File 'lib/rbs/definition.rb', line 146 def comments @comments ||= defs.map(&:comment).compact.uniq end |
#defined_in ⇒ Object
128 129 130 131 132 133 |
# File 'lib/rbs/definition.rb', line 128 def defined_in @defined_in ||= begin last_def = defs.last or raise last_def.defined_in end end |
#hash ⇒ Object
124 125 126 |
# File 'lib/rbs/definition.rb', line 124 def hash self.class.hash ^ super_method.hash ^ defs.hash ^ accessibility.hash ^ annotations.hash ^ alias_of.hash end |
#implemented_in ⇒ Object
135 136 137 138 139 140 |
# File 'lib/rbs/definition.rb', line 135 def implemented_in @implemented_in ||= begin last_def = defs.last or raise last_def.implemented_in end end |
#map_method_type(&block) ⇒ Object
185 186 187 188 189 |
# File 'lib/rbs/definition.rb', line 185 def map_method_type(&block) update( defs: defs.map {|defn| defn.update(type: yield(defn.type)) }, ) end |
#map_type(&block) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/rbs/definition.rb', line 171 def map_type(&block) update( super_method: super_method&.map_type(&block), defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) } ) end |
#map_type_bound(&block) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/rbs/definition.rb', line 178 def map_type_bound(&block) update( super_method: super_method&.map_type_bound(&block), defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) } ) end |
#members ⇒ Object
150 151 152 |
# File 'lib/rbs/definition.rb', line 150 def members @members ||= defs.map(&:member).uniq end |
#method_types ⇒ Object
142 143 144 |
# File 'lib/rbs/definition.rb', line 142 def method_types @method_types ||= defs.map(&:type) end |
#private? ⇒ Boolean
158 159 160 |
# File 'lib/rbs/definition.rb', line 158 def private? @accessibility == :private end |
#public? ⇒ Boolean
154 155 156 |
# File 'lib/rbs/definition.rb', line 154 def public? @accessibility == :public end |
#sub(s) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/rbs/definition.rb', line 162 def sub(s) return self if s.empty? update( super_method: super_method&.sub(s), defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) } ) end |
#update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations, alias_member: self.alias_member) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/rbs/definition.rb', line 191 def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations, alias_member: self.alias_member) self.class.new( super_method: super_method, defs: defs, accessibility: accessibility, alias_of: alias_of, alias_member: alias_member ).tap do |method| method.annotations.replace(annotations) end end |