Class: PHP::Method::Call

Inherits:
PHP::Expression show all
Defined in:
lib/php/syntax/method.rb

Overview

See Also:

Instance Attribute Summary

Instance Method Summary

Methods inherited from PHP::Node

#<<, #<=>, #children?, #each, #indent, #indent=, #to_s

Constructor Details

- (Call) initialize(receiver, method, *arguments)

A new instance of Call

Parameters:



24
25
26
27
28
# File 'lib/php/syntax/method.rb', line 24

def initialize(receiver, method, *arguments)
  @receiver  = receiver
  @method    = Identifier.new(method).to_sym
  @arguments = arguments
end

Instance Attribute Details

- (Array<Expression>) arguments

Returns:



18
19
20
# File 'lib/php/syntax/method.rb', line 18

def arguments
  @arguments
end

- (Symbol) method

Returns:

  • (Symbol)


14
15
16
# File 'lib/php/syntax/method.rb', line 14

def method
  @method
end

- (Expression) receiver

Returns:



10
11
12
# File 'lib/php/syntax/method.rb', line 10

def receiver
  @receiver
end

Instance Method Details

- (String) to_php

Returns the PHP representation of this method call.

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/php/syntax/method.rb', line 34

def to_php
  case method
    when :new
      if arguments.empty?
        "new #{receiver}"
      else
        "new #{receiver}(#{arguments.join(', ')})"
      end
    when :[]
      raise "expected a PHP::Literal, got #{arguments.first.inspect}" unless arguments.first.is_a?(Literal)
      case arguments.first.value
        when Symbol
          "#{receiver}->#{arguments.first}"
        else
          "#{receiver}[#{arguments.join(', ')}]"
      end
    else
      "#{receiver}->#{method}(#{arguments.join(', ')})"
  end
end