class Estreet::Identifier
Constants
- JS_IDENTIFIER
Public Class Methods
[](name)
click to toggle source
Returns an identifier created with name, or returns name if it is already an identifier.
# File lib/estreet/identifier.rb, line 23 def self.[](name) return name if name.is_a?(self) new(name) end
new(name)
click to toggle source
@param [Estreet::Identifier, String]
# File lib/estreet/identifier.rb, line 4 def initialize(name) raise ArgumentError, "Invalid identifier: #{name}" unless self.class.valid?(name) @name = name.to_s end
valid?(name)
click to toggle source
@returns true if name is a valid identifier.
# File lib/estreet/identifier.rb, line 29 def self.valid?(name) !!JS_IDENTIFIER.match(name.to_s) end
Public Instance Methods
attributes()
click to toggle source
Calls superclass method
# File lib/estreet/identifier.rb, line 9 def attributes super.merge(name: @name) end
to_pattern()
click to toggle source
# File lib/estreet/identifier.rb, line 13 def to_pattern self end
to_s()
click to toggle source
Returns the identifier as a Ruby string.
# File lib/estreet/identifier.rb, line 18 def to_s @name.to_s # this allows us to do Identifier.new(Identifier.new('hello')) and get an identifier end