Class: Fukubukuro::Program
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Sequence
#call, #inspect, #pretty_print
Constructor Details
#initialize(statements = , environment = Environment.new) ⇒ Program
Returns a new instance of Program.
120
121
122
123
|
# File 'lib/amber/fukubukuro.rb', line 120
def initialize statements = Sequence[], environment = Environment.new
super(statements)
self.environment = environment
end
|
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
119
120
121
|
# File 'lib/amber/fukubukuro.rb', line 119
def environment
@environment
end
|
Class Method Details
124
125
126
|
# File 'lib/amber/fukubukuro.rb', line 124
def self.inspect
'Program'
end
|
Instance Method Details
#amber_to_ruby(container) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/amber/fukubukuro.rb', line 130
def amber_to_ruby container
if container.respond_to? :to_ruby
container.to_ruby
else
container
end
end
|
#execute(env) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/amber/fukubukuro.rb', line 137
def execute env
if env.is_a? Hash
for name in env.keys
environment[name.to_sym].value = ruby_to_amber env[name]
end
else
raise 'Expected Hash as environment, got %p' % [env]
end
result = call
if env.is_a? Hash
for name, variable in environment
env[name] = env[name.to_s] = amber_to_ruby(variable.value)
end
end
amber_to_ruby result
end
|
153
154
155
|
# File 'lib/amber/fukubukuro.rb', line 153
def optimize
self
end
|
#ruby_to_amber(object) ⇒ Object
127
128
129
|
# File 'lib/amber/fukubukuro.rb', line 127
def ruby_to_amber object
raise NotImplementedError
end
|