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:) ⇒ Method

Returns a new instance of Method.



54
55
56
57
58
# File 'lib/rbs/definition.rb', line 54

def initialize(super_method:, defs:, accessibility:)
  @super_method = super_method
  @defs = defs
  @accessibility = accessibility
end

Instance Attribute Details

#accessibilityObject (readonly)

Returns the value of attribute accessibility.



52
53
54
# File 'lib/rbs/definition.rb', line 52

def accessibility
  @accessibility
end

#defsObject (readonly)

Returns the value of attribute defs.



51
52
53
# File 'lib/rbs/definition.rb', line 51

def defs
  @defs
end

#super_methodObject (readonly)

Returns the value of attribute super_method.



50
51
52
# File 'lib/rbs/definition.rb', line 50

def super_method
  @super_method
end

Instance Method Details

#annotationsObject



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

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

#attributesObject

Deprecated.


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

def attributes
  []
end

#commentsObject



72
73
74
# File 'lib/rbs/definition.rb', line 72

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

#defined_inObject



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

def defined_in
  @defined_in ||= defs.last.defined_in
end

#implemented_inObject



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

def implemented_in
  @implemented_in ||= defs.last.implemented_in
end

#map_method_type(&block) ⇒ Object



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

def map_method_type(&block)
  self.class.new(
    super_method: super_method,
    defs: defs.map {|defn| defn.update(type: yield(defn.type)) },
    accessibility: @accessibility
  )
end

#map_type(&block) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/rbs/definition.rb', line 101

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
  )
end

#method_typesObject



68
69
70
# File 'lib/rbs/definition.rb', line 68

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

#private?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/rbs/definition.rb', line 89

def private?
  @accessibility == :private
end

#public?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/rbs/definition.rb', line 85

def public?
  @accessibility == :public
end

#sub(s) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/rbs/definition.rb', line 93

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
  )
end