Class: Peruby::Op::PackageBlock
Overview
Temporarily changes the current package for one lexical block.
Instance Method Summary collapse
-
#initialize(name, body) ⇒ PackageBlock
constructor
A new instance of PackageBlock.
- #run(env, context) ⇒ Object
- #to_callable ⇒ Object
Methods inherited from Base
#argument_cells, #local_slot, #lvalue, #run_subroutine, #warning_directive?
Constructor Details
#initialize(name, body) ⇒ PackageBlock
Returns a new instance of PackageBlock.
138 139 140 141 |
# File 'lib/peruby/op/control.rb', line 138 def initialize(name, body) @name = name @body = body end |
Instance Method Details
#run(env, context) ⇒ Object
143 |
# File 'lib/peruby/op/control.rb', line 143 def run(env, context) = env.with_package(@name) { @body.run(env, context) } |
#to_callable ⇒ Object
145 146 147 148 |
# File 'lib/peruby/op/control.rb', line 145 def to_callable body = @body.to_callable ->(env, context) { env.with_package(@name) { body.call(env, context) } } end |