Class: Peruby::Op::PackageBlock

Inherits:
Base
  • Object
show all
Defined in:
lib/peruby/op/control.rb

Overview

Temporarily changes the current package for one lexical block.

Instance Method Summary collapse

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_callableObject



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