Class: Laser::Analysis::ArgumentExpansion
- Inherits:
-
Object
- Object
- Laser::Analysis::ArgumentExpansion
- Defined in:
- lib/laser/analysis/argument_expansion.rb
Overview
This class handles the interpretation and expansion of arguments being passed to a method call.
Instance Attribute Summary (collapse)
-
- (Object) node
readonly
Returns the value of attribute node.
Instance Method Summary (collapse)
-
- (Object) arity
Returns the arity of the argument block being passed, as a range of possible values.
-
- (Object) block_arg
Returns the block argument (&blk) for the argument expansion.
-
- (Object) constant_values
Returns an array of constant values that are the arguments being passed.
-
- (Boolean) empty?
Are there no arguments being passed?.
-
- (Boolean) has_block?
Returns whether the node has a block argument.
-
- (ArgumentExpansion) initialize(node)
constructor
args_add_block node.
-
- (Boolean) is_constant?
Returns whether all arguments are constant.
Constructor Details
- (ArgumentExpansion) initialize(node)
args_add_block node.
9 10 11 12 |
# File 'lib/laser/analysis/argument_expansion.rb', line 9 def initialize(node) node = node[1] if !node.nil? && node.type == :arg_paren @node = node end |
Instance Attribute Details
- (Object) node (readonly)
Returns the value of attribute node
6 7 8 |
# File 'lib/laser/analysis/argument_expansion.rb', line 6 def node @node end |
Instance Method Details
- (Object) arity
Returns the arity of the argument block being passed, as a range of possible values.
26 27 28 29 |
# File 'lib/laser/analysis/argument_expansion.rb', line 26 def arity return Arity::EMPTY if node.nil? Arity.new(arity_for_node(node)) end |
- (Object) block_arg
Returns the block argument (&blk) for the argument expansion.
51 52 53 54 |
# File 'lib/laser/analysis/argument_expansion.rb', line 51 def block_arg return false if node.nil? block_arg_for_node node end |
- (Object) constant_values
Returns an array of constant values that are the arguments being passed.
pre-contract: is_constant?.should be_true
45 46 47 48 |
# File 'lib/laser/analysis/argument_expansion.rb', line 45 def constant_values return [] if node.nil? node_constant_values(node) end |
- (Boolean) empty?
Are there no arguments being passed?
32 33 34 |
# File 'lib/laser/analysis/argument_expansion.rb', line 32 def empty? arity == (0..0) end |
- (Boolean) has_block?
Returns whether the node has a block argument. If it does, it returns the block argument's node.
16 17 18 19 20 21 22 |
# File 'lib/laser/analysis/argument_expansion.rb', line 16 def has_block? if node.nil? false elsif node.type == :args_add_block node[2] end end |
- (Boolean) is_constant?
Returns whether all arguments are constant.
37 38 39 40 |
# File 'lib/laser/analysis/argument_expansion.rb', line 37 def is_constant? return true if node.nil? node_is_constant?(node) end |