Class: Peruby::Op::Printf

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

Overview

Formatted output using the Perl sprintf compatibility layer.

Instance Method Summary collapse

Methods inherited from Base

#argument_cells, #local_slot, #lvalue, #run_subroutine, #to_callable, #warning_directive?

Constructor Details

#initialize(handle, arguments) ⇒ Printf

Returns a new instance of Printf.



24
25
26
27
# File 'lib/peruby/op/io.rb', line 24

def initialize(handle, arguments)
  @handle = handle
  @arguments = arguments
end

Instance Method Details

#run(env, context) ⇒ Object



29
30
31
32
33
34
# File 'lib/peruby/op/io.rb', line 29

def run(env, context)
  values = @arguments&.run(env, :list) || []
  format = Conv.to_str(values.shift&.get)
  env.runtime.output(@handle, env).print(Sprintf.format(format, values.map(&:get)))
  context == :list ? [Scalar.new(1)] : 1
end