Class: Peruby::NativeBody
- Inherits:
-
Object
- Object
- Peruby::NativeBody
- Defined in:
- lib/peruby/runtime/code.rb
Overview
Adapter for core-module functions implemented in Ruby.
Instance Method Summary collapse
-
#initialize(&block) ⇒ NativeBody
constructor
A new instance of NativeBody.
- #run_subroutine(env, context) ⇒ Object
Constructor Details
#initialize(&block) ⇒ NativeBody
Returns a new instance of NativeBody.
10 11 12 |
# File 'lib/peruby/runtime/code.rb', line 10 def initialize(&block) @block = block end |
Instance Method Details
#run_subroutine(env, context) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/peruby/runtime/code.rb', line 14 def run_subroutine(env, context) result = @block.call(env, env.fetch(:array, '_').cells, context) return Array(result).map { |value| value.is_a?(Scalar) ? value : Scalar.new(value) } if context == :list result.is_a?(Scalar) ? result.get : result end |