Class: RBS::Definition::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/definition.rb

Defined Under Namespace

Classes: TypeDef

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:) ⇒ Method

Returns a new instance of Method.



81
82
83
84
85
86
87
# File 'lib/rbs/definition.rb', line 81

def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:)
  @super_method = super_method
  @defs = defs
  @accessibility = accessibility
  @extra_annotations = annotations
  @alias_of = alias_of
end

Instance Attribute Details

#accessibilityObject (readonly)

Returns the value of attribute accessibility.



77
78
79
# File 'lib/rbs/definition.rb', line 77

def accessibility
  @accessibility
end

#alias_ofObject (readonly)

Returns the value of attribute alias_of.



79
80
81
# File 'lib/rbs/definition.rb', line 79

def alias_of
  @alias_of
end

#defsObject (readonly)

Returns the value of attribute defs.



76
77
78
# File 'lib/rbs/definition.rb', line 76

def defs
  @defs
end

#extra_annotationsObject (readonly)

Returns the value of attribute extra_annotations.



78
79
80
# File 'lib/rbs/definition.rb', line 78

def extra_annotations
  @extra_annotations
end

#super_methodObject (readonly)

Returns the value of attribute super_method.



75
76
77
# File 'lib/rbs/definition.rb', line 75

def super_method
  @super_method
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



89
90
91
92
93
94
95
96
# File 'lib/rbs/definition.rb', line 89

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

#annotationsObject



126
127
128
# File 'lib/rbs/definition.rb', line 126

def annotations
  @annotations ||= @extra_annotations + defs.flat_map {|d| d.annotations }
end

#commentsObject



122
123
124
# File 'lib/rbs/definition.rb', line 122

def comments
  @comments ||= defs.map(&:comment).compact.uniq
end

#defined_inObject



104
105
106
107
108
109
# File 'lib/rbs/definition.rb', line 104

def defined_in
  @defined_in ||= begin
    last_def = defs.last or raise
    last_def.defined_in
  end
end

#hashObject



100
101
102
# File 'lib/rbs/definition.rb', line 100

def hash
  self.class.hash ^ super_method.hash ^ defs.hash ^ accessibility.hash ^ annotations.hash ^ alias_of.hash
end

#implemented_inObject



111
112
113
114
115
116
# File 'lib/rbs/definition.rb', line 111

def implemented_in
  @implemented_in ||= begin
    last_def = defs.last or raise
    last_def.implemented_in
  end
end

#map_method_type(&block) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/rbs/definition.rb', line 169

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



151
152
153
154
155
156
157
158
# File 'lib/rbs/definition.rb', line 151

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



160
161
162
163
164
165
166
167
# File 'lib/rbs/definition.rb', line 160

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

#membersObject



130
131
132
# File 'lib/rbs/definition.rb', line 130

def members
  @members ||= defs.map(&:member).uniq
end

#method_typesObject



118
119
120
# File 'lib/rbs/definition.rb', line 118

def method_types
  @method_types ||= defs.map(&:type)
end

#private?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/rbs/definition.rb', line 138

def private?
  @accessibility == :private
end

#public?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/rbs/definition.rb', line 134

def public?
  @accessibility == :public
end

#sub(s) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/rbs/definition.rb', line 142

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



178
179
180
181
182
183
184
185
186
# File 'lib/rbs/definition.rb', line 178

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