Class: RubyLisp::Symbol
Instance Attribute Summary
Attributes inherited from Value
#value
Instance Method Summary
collapse
Methods inherited from Value
#initialize
Instance Method Details
#==(other) ⇒ Object
80
81
82
|
# File 'lib/rubylisp/types.rb', line 80
def ==(other)
other.is_a?(Symbol) && @value == other.value
end
|
#resolve(env) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/rubylisp/types.rb', line 84
def resolve(env)
instance_method = /^\.(.*)/.match(@value).to_a[1]
if instance_method
return lambda {|obj, *args| obj.send instance_method, *args}
end
if /^\w+(::\w+)+$/ =~ @value
first_segment, *segments = @value.split('::')
first_segment = Object.const_get first_segment
return segments.reduce(first_segment) do |result, segment|
if result.is_a? Proc
raise RuntimeError, "Invalid value: #{@value}"
elsif /^[A-Z]/ =~ segment
result.const_get segment
else
result.send segment unless result.respond_to? segment
lambda {|*args| result.send segment, *args }
end
end
end
env.get @value
end
|
#to_s ⇒ Object
76
77
78
|
# File 'lib/rubylisp/types.rb', line 76
def to_s
@value
end
|