class Method
A Ruby-specific method.
Definitions
def initialize(*arguments, receiver: nil, **options)
Initialize a new method definition.
Signature
-
parameter
arguments
Array
The definition arguments.
-
parameter
receiver
String
The method receiver (for class methods).
-
parameter
options
Hash
Additional options.
Implementation
def initialize(*arguments, receiver: nil, **options)
super(*arguments, **options)
@receiver = receiver
end
def nested_name
Generate a nested name for the method.
Implementation
def nested_name
if @receiver
".#{self.name}"
else
"##{self.name}"
end
end
def short_form
The short form of the method.
e.g. def puts
or def self.puts
.
Implementation
def short_form
if @receiver
"def #{@receiver}.#{@node.name}"
else
"def #{@node.name}"
end
end
def arguments_node
The node which contains the function arguments.
Implementation
def arguments_node
@node.parameters
end
def long_form
The long form of the method.
e.g. def puts(*lines, separator: "\n")
or def self.puts(*lines, separator: "\n")
.
Implementation
def long_form
if arguments_node = self.arguments_node
if @receiver
"def #{@receiver}.#{@node.name}(#{arguments_node.location.slice})"
else
"def #{@node.name}(#{arguments_node.location.slice})"
end
else
self.short_form
end
end
def qualified_form
The fully qualified name of the block.
e.g. ::Barnyard#foo
.
Implementation
def qualified_form
self.qualified_name
end
def qualified_name
Override the qualified_name method to handle method name joining correctly
Implementation
def qualified_name
@qualified_name ||= begin
if @parent
[@parent.qualified_name, self.nested_name].join("")
else
self.nested_name
end
end
end
def convert(kind)
Convert the method to a different kind of definition.
Signature
-
parameter
kind
Symbol
The kind to convert to.
Implementation
def convert(kind)
case kind
when :attribute
Attribute.new(@node, @name,
comments: @comments, parent: @parent, language: @language
)
else
super
end
end