Class: PHP::Class

Inherits:
PHP::Interface show all
Defined in:
lib/php/syntax/class.rb

Overview

See Also:

Instance Attribute Summary

Instance Method Summary

Methods inherited from PHP::Node

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

Constructor Details

- (Class) initialize(name, options = {})

A new instance of Class

Parameters:

  • (Symbol, #to_s) name
  • (Hash{Symbol => Object} options) Hash{Symbol — => Object} options


16
17
18
# File 'lib/php/syntax/class.rb', line 16

def initialize(name, options = {})
  @name, @options = Identifier.new(name).to_sym, options
end

Instance Attribute Details

- (Array<Node>) methods

Returns:



11
12
13
# File 'lib/php/syntax/class.rb', line 11

def methods
  @methods
end

- (Symbol) name

Returns:

  • (Symbol)


7
8
9
# File 'lib/php/syntax/class.rb', line 7

def name
  @name
end

Instance Method Details

- (Symbol) extends Also known as: superclass, parent

Returns the name of the superclass, if any, for this class.

Returns:

  • (Symbol)


32
33
34
# File 'lib/php/syntax/class.rb', line 32

def extends
  @options[:extends] rescue nil
end

- (Boolean) extends?

Returns true if this class has a defined superclass.

Returns:

  • (Boolean)


24
25
26
# File 'lib/php/syntax/class.rb', line 24

def extends?
  !@options[:extends].nil?
end

- (String) to_php

Returns the PHP representation of this class.

Returns:

  • (String)


43
44
45
46
47
48
49
# File 'lib/php/syntax/class.rb', line 43

def to_php
  if extends?
    "class #{name} extends #{extends} {}" # TODO
  else
    "class #{name} {}" # TODO
  end
end