Class: Peruby::Op::Printf
Overview
Formatted output using the Perl sprintf compatibility layer.
Instance Method Summary collapse
-
#initialize(handle, arguments) ⇒ Printf
constructor
A new instance of Printf.
- #run(env, context) ⇒ Object
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 |