Class: PHP::Identifier

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

Overview

See Also:

Constant Summary

SYNTAX =
/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Methods inherited from PHP::Node

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

Constructor Details

- (Identifier) initialize(name)

A new instance of Identifier

Parameters:

  • (Symbol, #to_s) name


22
23
24
25
26
27
28
29
# File 'lib/php/syntax/identifier.rb', line 22

def initialize(name)
  @name = case name
    when Symbol then name
    else
      raise ArgumentError.new("invalid PHP identifier name: #{name.inspect}") unless self.class.valid_name?(name)
      name.to_s.to_sym
  end
end

Instance Attribute Details

- (Symbol) name

Returns:

  • (Symbol)


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

def name
  @name
end

Class Method Details

+ (Boolean) valid_name?(name)

Returns true if name is a valid PHP variable name.

Parameters:

  • (Symbol, #to_s) name

Returns:

  • (Boolean)


12
13
14
# File 'lib/php/syntax/identifier.rb', line 12

def self.valid_name?(name)
  !(name.to_s =~ SYNTAX).nil?
end

Instance Method Details

- (Integer) <=>(other)

Compares this identifier to other for sorting purposes.

Returns:

  • (Integer) — -1, 0, 1


35
36
37
# File 'lib/php/syntax/identifier.rb', line 35

def <=>(other)
  to_s <=> other.to_s
end

- (String) to_php

Returns the PHP representation of this identifier.

Returns:

  • (String)


43
44
45
# File 'lib/php/syntax/identifier.rb', line 43

def to_php
  name.to_s
end

- (Symbol) to_sym

Returns the symbolic representation of this identifier.

Returns:

  • (Symbol)


51
52
53
# File 'lib/php/syntax/identifier.rb', line 51

def to_sym
  name
end