Class: Heist::Runtime::Identifier

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Expression
Defined in:
lib/heist/runtime/data/identifier.rb

Overview

An Identifier is used to represent any name that appears in Scheme code. We might throw it away and use symbols at some point. I had this idea for storing metadata on Identifier objects to speed things up but it pretty much came to nothing. Its one saving grace is that it needs to be treated as an Expression class, and also that we need to store some extra metadata on Identifier objects, and I don’t want to modify core Ruby classes

Instance Attribute Summary

Attributes included from Expression

#parent

Instance Method Summary collapse

Methods included from Expression

#eval, #replace

Constructor Details

#initialize(name, orginal_name = nil) ⇒ Identifier

An Identifier is initialized using a string that becomes the name of the identifier. The optional second parameter is used to specify the original name of an identifier if it has been renamed during a macro expansion.



22
23
24
25
# File 'lib/heist/runtime/data/identifier.rb', line 22

def initialize(name, orginal_name = nil)
  @name = name.to_s
  @orginal_name = (orginal_name || name).to_s
end

Instance Method Details

#==(other) ⇒ Object

Returns true if the receiver has the same name as the argument.



32
33
34
35
# File 'lib/heist/runtime/data/identifier.rb', line 32

def ==(other)
  return true if Binding === other and other == self
  Identifier === other and @orginal_name.downcase == other.name.downcase
end

#nameObject



27
28
29
# File 'lib/heist/runtime/data/identifier.rb', line 27

def name
  @orginal_name
end

#to_rubyObject

Returns a raw Ruby representation of the identifier, for which we use symbols.



39
40
41
# File 'lib/heist/runtime/data/identifier.rb', line 39

def to_ruby
  @name.to_s.to_sym
end