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.



65
66
67
68
69
70
71
# File 'lib/rbs/definition.rb', line 65

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.



61
62
63
# File 'lib/rbs/definition.rb', line 61

def accessibility
  @accessibility
end

#alias_ofObject (readonly)

Returns the value of attribute alias_of.



63
64
65
# File 'lib/rbs/definition.rb', line 63

def alias_of
  @alias_of
end

#defsObject (readonly)

Returns the value of attribute defs.



60
61
62
# File 'lib/rbs/definition.rb', line 60

def defs
  @defs
end

#extra_annotationsObject (readonly)

Returns the value of attribute extra_annotations.



62
63
64
# File 'lib/rbs/definition.rb', line 62

def extra_annotations
  @extra_annotations
end

#super_methodObject (readonly)

Returns the value of attribute super_method.



59
60
61
# File 'lib/rbs/definition.rb', line 59

def super_method
  @super_method
end

Instance Method Details

#annotationsObject



95
96
97
# File 'lib/rbs/definition.rb', line 95

def annotations
  @annotations ||= @extra_annotations + defs.flat_map(&:annotations)
end

#commentsObject



91
92
93
# File 'lib/rbs/definition.rb', line 91

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

#defined_inObject



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

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

#implemented_inObject



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

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

#map_method_type(&block) ⇒ Object



129
130
131
132
133
134
135
136
# File 'lib/rbs/definition.rb', line 129

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



120
121
122
123
124
125
126
127
# File 'lib/rbs/definition.rb', line 120

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

#membersObject



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

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

#method_typesObject



87
88
89
# File 'lib/rbs/definition.rb', line 87

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

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  @accessibility == :private
end

#public?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/rbs/definition.rb', line 103

def public?
  @accessibility == :public
end

#sub(s) ⇒ Object



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

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