Class: RBS::AST::Members::MethodDefinition

Inherits:
Base
  • Object
show all
Includes:
_ToJson, _HashEqual
Defined in:
lib/rbs/ast/members.rb,
sig/members.rbs

Defined Under Namespace

Classes: Overload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, kind:, overloads:, annotations:, location:, comment:, overloading:, visibility:) ⇒ MethodDefinition

Returns a new instance of MethodDefinition.

Parameters:



55
56
57
58
59
60
61
62
63
64
# File 'lib/rbs/ast/members.rb', line 55

def initialize(name:, kind:, overloads:, annotations:, location:, comment:, overloading:, visibility:)
  @name = name
  @kind = kind
  @overloads = overloads
  @annotations = annotations
  @location = location
  @comment = comment
  @overloading = overloading
  @visibility = visibility
end

Instance Attribute Details

#annotationsArray[Annotation] (readonly)

Returns the value of attribute annotations.

Returns:



49
50
51
# File 'lib/rbs/ast/members.rb', line 49

def annotations
  @annotations
end

#commentComment? (readonly)

Returns the value of attribute comment.

Returns:



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

def comment
  @comment
end

#kindkind (readonly)

Returns the value of attribute kind.

Returns:



47
48
49
# File 'lib/rbs/ast/members.rb', line 47

def kind
  @kind
end

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


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

def location
  @location
end

#nameSymbol (readonly)

Returns the value of attribute name.

Returns:

  • (Symbol)


46
47
48
# File 'lib/rbs/ast/members.rb', line 46

def name
  @name
end

#overloadingBoolean (readonly)

Returns the value of attribute overloading.

Returns:

  • (Boolean)


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

def overloading
  @overloading
end

#overloadsArray[Overload] (readonly)

Returns the value of attribute overloads.

Returns:



48
49
50
# File 'lib/rbs/ast/members.rb', line 48

def overloads
  @overloads
end

#visibilityvisibility? (readonly)

Returns the value of attribute visibility.

Returns:



53
54
55
# File 'lib/rbs/ast/members.rb', line 53

def visibility
  @visibility
end

Instance Method Details

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



66
67
68
69
70
71
72
73
# File 'lib/rbs/ast/members.rb', line 66

def ==(other)
  other.is_a?(MethodDefinition) &&
    other.name == name &&
    other.kind == kind &&
    other.overloads == overloads &&
    other.overloading? == overloading? &&
    other.visibility == visibility
end

#hashObject



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

def hash
  name.hash ^ kind.hash ^ overloads.hash ^ overloading?.hash ^ visibility.hash
end

#instance?Boolean

Returns true if the def is to define instance method

Returns:

  • (Boolean)


68
69
70
# File 'sig/members.rbs', line 68

def instance?
  kind == :instance || kind == :singleton_instance
end

#overloading?Boolean

Returns true if the def is overloading (== with ...)

Returns:

  • (Boolean)


75
76
77
# File 'sig/members.rbs', line 75

def overloading?
  overloading
end

#singleton?Boolean

Returns true if the def is to define singleton method

Returns:

  • (Boolean)


71
72
73
# File 'sig/members.rbs', line 71

def singleton?
  kind == :singleton || kind == :singleton_instance
end

#to_json(state = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rbs/ast/members.rb', line 106

def to_json(state = nil)
  {
    member: :method_definition,
    name: name,
    kind: kind,
    overloads: overloads,
    annotations: annotations,
    location: location,
    comment: comment,
    overloading: overloading?,
    visibility: visibility
  }.to_json(state)
end

#update(name: self.name, kind: self.kind, overloads: self.overloads, annotations: self.annotations, location: self.location, comment: self.comment, overloading: self.overloading?, visibility: self.visibility) ⇒ MethodDefinition

Parameters:

  • name: (Symbol) (defaults to: self.name)
  • kind: (kind) (defaults to: self.kind)
  • overloads: (Array[Overload]) (defaults to: self.overloads)
  • annotations: (Array[Annotation]) (defaults to: self.annotations)
  • location: (loc, nil) (defaults to: self.location)
  • comment: (Comment, nil) (defaults to: self.comment)
  • overloading: (Boolean) (defaults to: self.overloading?)
  • visibility: (visibility, nil) (defaults to: self.visibility)

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rbs/ast/members.rb', line 93

def update(name: self.name, kind: self.kind, overloads: self.overloads, annotations: self.annotations, location: self.location, comment: self.comment, overloading: self.overloading?, visibility: self.visibility)
  self.class.new(
    name: name,
    kind: kind,
    overloads: overloads,
    annotations: annotations,
    location: location,
    comment: comment,
    overloading: overloading,
    visibility: visibility
  )
end