Class: Rubyzen::Declarations::ReturnDeclaration
- Inherits:
-
Object
- Object
- Rubyzen::Declarations::ReturnDeclaration
- Includes:
- Providers::ClassNameProvider, Providers::FilePathProvider, Providers::LineNumberProvider, Providers::SourceCodeProvider
- Defined in:
- lib/rubyzen/declarations/return_declaration.rb
Overview
Represents a single point at which a method or block yields a value: the implicit final expression of its body, or an explicit return statement.
Instance Attribute Summary collapse
-
#node ⇒ RuboCop::AST::Node
readonly
The
returnnode, or the implicit final-expression node. -
#parent ⇒ MethodDeclaration, BlockDeclaration
readonly
The declaration that returns this value.
Instance Method Summary collapse
-
#explicit? ⇒ Boolean
True if this is an explicit
returnstatement. -
#expression ⇒ ExpressionDeclaration?
The value expression being returned.
-
#implicit? ⇒ Boolean
True if this is the implicit final expression of the body.
-
#initialize(node, parent) ⇒ ReturnDeclaration
constructor
A new instance of ReturnDeclaration.
Methods included from Providers::SourceCodeProvider
Methods included from Providers::ClassNameProvider
Methods included from Providers::LineNumberProvider
Methods included from Providers::FilePathProvider
Constructor Details
#initialize(node, parent) ⇒ ReturnDeclaration
Returns a new instance of ReturnDeclaration.
25 26 27 28 |
# File 'lib/rubyzen/declarations/return_declaration.rb', line 25 def initialize(node, parent) @node = node @parent = parent end |
Instance Attribute Details
#node ⇒ RuboCop::AST::Node (readonly)
Returns the return node, or the implicit final-expression node.
18 19 20 |
# File 'lib/rubyzen/declarations/return_declaration.rb', line 18 def node @node end |
#parent ⇒ MethodDeclaration, BlockDeclaration (readonly)
Returns the declaration that returns this value.
21 22 23 |
# File 'lib/rubyzen/declarations/return_declaration.rb', line 21 def parent @parent end |
Instance Method Details
#explicit? ⇒ Boolean
Returns true if this is an explicit return statement.
31 32 33 |
# File 'lib/rubyzen/declarations/return_declaration.rb', line 31 def explicit? node.return_type? end |
#expression ⇒ ExpressionDeclaration?
The value expression being returned.
43 44 45 46 47 48 |
# File 'lib/rubyzen/declarations/return_declaration.rb', line 43 def expression value_node = explicit? ? node.children.first : node return nil if value_node.nil? ExpressionDeclaration.new(value_node, self) end |
#implicit? ⇒ Boolean
Returns true if this is the implicit final expression of the body.
36 37 38 |
# File 'lib/rubyzen/declarations/return_declaration.rb', line 36 def implicit? !explicit? end |