Class: Nydp::Symbol

Inherits:
Object show all
Defined in:
lib/nydp/symbol.rb

Defined Under Namespace

Classes: Unbound

Constant Summary collapse

EMPTY =
:""

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Symbol

Returns a new instance of Symbol.



10
11
12
13
14
15
# File 'lib/nydp/symbol.rb', line 10

def initialize name
  name = name.to_s
  @name = name.to_sym
  raise "cannot be symbol : #{name.inspect}" if @name == :nil || @name == :t
  @inspection = "|#{name.gsub(/\|/, '\|')}|" if untidy(name)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/nydp/symbol.rb', line 4

def name
  @name
end

Class Method Details

.find(name, ns) ⇒ Object



41
# File 'lib/nydp/symbol.rb', line 41

def self.find name, ns ; ns[name.to_sym] ;  end

.new(name) ⇒ Object



6
7
8
# File 'lib/nydp/symbol.rb', line 6

def self.new name
  special(name.to_s.to_sym) || super
end

.special(name) ⇒ Object



35
36
37
38
39
# File 'lib/nydp/symbol.rb', line 35

def self.special name
  return nil  if name == :nil
  return true if name == :t
  nil
end

Instance Method Details

#<(other) ⇒ Object



50
# File 'lib/nydp/symbol.rb', line 50

def <             other ; self.name < other.name   ; end

#<=>(other) ⇒ Object



51
# File 'lib/nydp/symbol.rb', line 51

def <=>           other ; self.name <=> other.name ; end

#==(other) ⇒ Object Also known as: eql?



59
60
61
# File 'lib/nydp/symbol.rb', line 59

def == other
  other.is_a?(Nydp::Symbol) && (self.name == other.name)
end

#>(other) ⇒ Object



49
# File 'lib/nydp/symbol.rb', line 49

def >             other ; self.name > other.name   ; end

#assign(value, _ = nil) ⇒ Object



52
# File 'lib/nydp/symbol.rb', line 52

def assign value, _=nil ; @value = value           ; end

#compile_to_ruby(indent, src, opts = nil) ⇒ Object



31
32
33
# File 'lib/nydp/symbol.rb', line 31

def compile_to_ruby indent, src, opts=nil
  "#{indent}ns.#{ruby_name}"
end

#hashObject

can't cache this, it seems to break when unmarshalling



17
# File 'lib/nydp/symbol.rb', line 17

def hash ; name.hash ; end

#inspectObject



44
# File 'lib/nydp/symbol.rb', line 44

def inspect             ; @inspection || name.to_s ; end

#is?(nm) ⇒ Boolean

Returns:

  • (Boolean)


48
# File 'lib/nydp/symbol.rb', line 48

def is?              nm ; self.name == nm.to_sym   ; end

#ns_assign(ns, value) ⇒ Object



54
55
56
57
# File 'lib/nydp/symbol.rb', line 54

def ns_assign ns, value
  value.is_named(@name) if value.respond_to?(:is_named)
  ns.send(:"#{ruby_name}=", value)
end

#nydp_typeObject



43
# File 'lib/nydp/symbol.rb', line 43

def nydp_type           ; :symbol                  ; end

#ruby_nameObject



27
28
29
# File 'lib/nydp/symbol.rb', line 27

def ruby_name
  "ns_#{name.to_s._nydp_name_to_rb_name}"
end

#to_rubyObject



47
# File 'lib/nydp/symbol.rb', line 47

def to_ruby             ; to_sym                   ; end

#to_sObject



45
# File 'lib/nydp/symbol.rb', line 45

def to_s                ; name.to_s                ; end

#to_symObject



46
# File 'lib/nydp/symbol.rb', line 46

def to_sym              ; name                     ; end

#untidy(str) ⇒ Object



19
20
21
# File 'lib/nydp/symbol.rb', line 19

def untidy str
  (str == "") || (str == nil) || (str =~ /[\s\|,\(\)"]/)
end

#value(context = nil) ⇒ Object



23
24
25
# File 'lib/nydp/symbol.rb', line 23

def value context=nil
  @value
end