Class: Puppet::Parser::AST::MethodCall
- Defined in:
- lib/puppet/parser/ast/method_call.rb
Overview
An AST object to call a method
Instance Attribute Summary collapse
-
#arguments ⇒ Array<Puppet::Parser::AST>
The arguments to evaluate as arguments to the method.
-
#lambda ⇒ Puppet::Parser::AST::Lambda
An optional lambda/block that will be yielded to by the called method (if it supports this).
-
#name ⇒ String
The name of the method.
-
#receiver ⇒ Puppet::Parser::AST
An AST that evaluates to the object the method is applied to.
Attributes inherited from Branch
Instance Method Summary collapse
-
#evaluate(scope) ⇒ Object
Evaluates the method call and returns what the called method/function returns.
-
#ignore_rvalue ⇒ void
Sets this method call in statement mode where a produced rvalue is ignored.
-
#initialize(hash) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #to_s ⇒ Object
Methods inherited from Branch
Constructor Details
#initialize(hash) ⇒ MethodCall
Returns a new instance of MethodCall.
57 58 59 60 61 62 63 64 |
# File 'lib/puppet/parser/ast/method_call.rb', line 57 def initialize(hash) @ftype = hash[:ftype] || :rvalue hash.delete(:ftype) if hash.include? :ftype super(hash) # Lastly, check the parity end |
Instance Attribute Details
#arguments ⇒ Array<Puppet::Parser::AST>
The arguments to evaluate as arguments to the method.
20 21 22 |
# File 'lib/puppet/parser/ast/method_call.rb', line 20 def arguments @arguments end |
#lambda ⇒ Puppet::Parser::AST::Lambda
An optional lambda/block that will be yielded to by the called method (if it supports this)
24 25 26 |
# File 'lib/puppet/parser/ast/method_call.rb', line 24 def lambda @lambda end |
#name ⇒ String
The name of the method
16 17 18 |
# File 'lib/puppet/parser/ast/method_call.rb', line 16 def name @name end |
#receiver ⇒ Puppet::Parser::AST
An AST that evaluates to the object the method is applied to
12 13 14 |
# File 'lib/puppet/parser/ast/method_call.rb', line 12 def receiver @receiver end |
Instance Method Details
#evaluate(scope) ⇒ Object
Evaluates the method call and returns what the called method/function returns. The evaluation evaluates all arguments in the calling scope and then delegates to a “method” instance produced by Puppet::Parser::Methods for this method call.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppet/parser/ast/method_call.rb', line 31 def evaluate(scope) # Make sure it's a defined method for the receiver r = @receiver.evaluate(scope) raise Puppet::ParseError, "No object to apply method #{@name} to" unless r m = Puppet::Parser::Methods.find_method(scope, r, @name) raise Puppet::ParseError, "Unknown method #{@name} for #{r}" unless m # Now check if rvalue is required (in expressions) case @ftype when :rvalue raise Puppet::ParseError, "Method '#{@name}' does not return a value" unless m.is_rvalue? when :statement # When used as a statement, ignore if it produces a rvalue (it is simply not used) else raise Puppet::DevError, "Invalid method type #{@ftype.inspect}" end # Evaluate arguments args = @arguments ? @arguments.safeevaluate(scope).map { |x| x == :undef ? '' : x } : [] # There is no need to evaluate the name, since it is a literal ruby string # call the method (it is already bound to the receiver and name) m.invoke(scope, args, @lambda) end |
#ignore_rvalue ⇒ void
This method returns an undefined value.
Sets this method call in statement mode where a produced rvalue is ignored.
68 69 70 |
# File 'lib/puppet/parser/ast/method_call.rb', line 68 def ignore_rvalue @ftype = :statement end |