Class: Peruby::Op::ReadlineCondition

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

Overview

Perl's readline-in-while shorthand assigns $_ and tests definedness.

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(readline) ⇒ ReadlineCondition

Returns a new instance of ReadlineCondition.



101
102
103
# File 'lib/peruby/op/io.rb', line 101

def initialize(readline)
  @readline = readline
end

Instance Method Details

#run(env, context) ⇒ Object



105
106
107
108
109
110
# File 'lib/peruby/op/io.rb', line 105

def run(env, context)
  value = @readline.run(env, :scalar)
  env.fetch(:scalar, '_').set(value)
  result = value.nil? ? '' : 1
  context == :list ? [Scalar.new(result)] : result
end