class Call
A Ruby-specific block which might carry other definitions.
Definitions
def container?
A block can sometimes be a container for other definitions.
Implementation
def container?
case block = @node&.block
when nil
false
when Prism::BlockArgumentNode
false
when Prism::BlockNode
# Technically, all block nodes are containers, but we prefer to be opinionated about when we consider them containers:
block.opening == "do"
else
false
end
end
def short_form
The short form of the class.
e.g. foo
.
Implementation
def short_form
if @node&.block && @node.block.opening == "{"
"#{name} { ... }"
else
name.to_s
end
end
def long_form
The long form of the class.
e.g. foo(:bar)
.
Implementation
def long_form
if @node.location.start_line == @node.location.end_line
@node.location.slice
else
# For multiline calls, use the actual call name with arguments
if @node.arguments && @node.arguments.arguments.any?
argument_text = @node.arguments.arguments.map{|argument| argument.location.slice}.join(", ")
"#{@node.name}(#{argument_text})"
else
@node.name.to_s
end
end
end
def qualified_form
The fully qualified name of the block.
e.g. class ::Barnyard::Dog
.
Implementation
def qualified_form
self.qualified_name
end