mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Cleanup method docs in AST::Scope
This commit is contained in:
parent
614fcfa6a8
commit
71de3f0012
1 changed files with 12 additions and 12 deletions
|
@ -71,7 +71,7 @@ module Ameba::AST
|
||||||
ivariables << InstanceVariable.new(node)
|
ivariables << InstanceVariable.new(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns variable by its name or nil if it does not exist.
|
# Returns variable by its name or `nil` if it does not exist.
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# scope = Scope.new(class_node, nil)
|
# scope = Scope.new(class_node, nil)
|
||||||
|
@ -91,13 +91,13 @@ module Ameba::AST
|
||||||
find_variable(name).try &.assign(node, self)
|
find_variable(name).try &.assign(node, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if current scope represents a block (or proc),
|
# Returns `true` if current scope represents a block (or proc),
|
||||||
# false if not.
|
# `false` otherwise.
|
||||||
def block?
|
def block?
|
||||||
node.is_a?(Crystal::Block) || node.is_a?(Crystal::ProcLiteral)
|
node.is_a?(Crystal::Block) || node.is_a?(Crystal::ProcLiteral)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if current scope represents a spawn block, e. g.
|
# Returns `true` if current scope represents a spawn block, e. g.
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# spawn do
|
# spawn do
|
||||||
|
@ -110,18 +110,18 @@ module Ameba::AST
|
||||||
call.try(&.name) == "spawn"
|
call.try(&.name) == "spawn"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if current scope sits inside a macro.
|
# Returns `true` if current scope sits inside a macro.
|
||||||
def in_macro?
|
def in_macro?
|
||||||
node.is_a?(Crystal::Macro) || !!outer_scope.try(&.in_macro?)
|
node.is_a?(Crystal::Macro) || !!outer_scope.try(&.in_macro?)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true instance variable assinged in this scope.
|
# Returns `true` if instance variable is assinged in this scope.
|
||||||
def assigns_ivar?(name)
|
def assigns_ivar?(name)
|
||||||
arguments.find(&.name.== name) &&
|
arguments.find(&.name.== name) &&
|
||||||
ivariables.find(&.name.== "@#{name}")
|
ivariables.find(&.name.== "@#{name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if and only if current scope represents some
|
# Returns `true` if and only if current scope represents some
|
||||||
# type definition, for example a class.
|
# type definition, for example a class.
|
||||||
def type_definition?
|
def type_definition?
|
||||||
node.is_a?(Crystal::ClassDef) ||
|
node.is_a?(Crystal::ClassDef) ||
|
||||||
|
@ -133,7 +133,7 @@ module Ameba::AST
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if current scope (or any of inner scopes) references variable,
|
# Returns true if current scope (or any of inner scopes) references variable,
|
||||||
# false if not.
|
# `false` otherwise.
|
||||||
def references?(variable : Variable, check_inner_scopes = true)
|
def references?(variable : Variable, check_inner_scopes = true)
|
||||||
variable.references.any? do |reference|
|
variable.references.any? do |reference|
|
||||||
return true if reference.scope == self
|
return true if reference.scope == self
|
||||||
|
@ -141,17 +141,17 @@ module Ameba::AST
|
||||||
end || variable.used_in_macro?
|
end || variable.used_in_macro?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if current scope is a def, false if not.
|
# Returns `true` if current scope is a def, `false` otherwise.
|
||||||
def def?
|
def def?
|
||||||
node.is_a?(Crystal::Def)
|
node.is_a?(Crystal::Def)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if this scope is a top level scope, false if not.
|
# Returns `true` if this scope is a top level scope, `false` otherwise.
|
||||||
def top_level?
|
def top_level?
|
||||||
outer_scope.nil?
|
outer_scope.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if var is an argument in current scope, false if not.
|
# Returns true if var is an argument in current scope, `false` otherwise.
|
||||||
def arg?(var)
|
def arg?(var)
|
||||||
case current_node = node
|
case current_node = node
|
||||||
when Crystal::Def
|
when Crystal::Def
|
||||||
|
@ -169,7 +169,7 @@ module Ameba::AST
|
||||||
args.any? { |arg| arg.name == var.name && arg.location == var.location }
|
args.any? { |arg| arg.name == var.name && arg.location == var.location }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the `node` represents exactly
|
# Returns `true` if the *node* represents exactly
|
||||||
# the same Crystal node as `@node`.
|
# the same Crystal node as `@node`.
|
||||||
def eql?(node)
|
def eql?(node)
|
||||||
node == @node &&
|
node == @node &&
|
||||||
|
|
Loading…
Reference in a new issue