Class: Peruby::Op::FileTest

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

Overview

Perl file-test operators backed by File::Stat predicates.

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(operator, expression) ⇒ FileTest

Returns a new instance of FileTest.



752
753
754
755
# File 'lib/peruby/op/builtin.rb', line 752

def initialize(operator, expression)
  @operator = operator.delete_prefix('-')
  @expression = expression
end

Instance Method Details

#run(env, context) ⇒ Object



757
758
759
760
761
762
763
# File 'lib/peruby/op/builtin.rb', line 757

def run(env, context)
  path = Conv.to_str(@expression.run(env, :scalar))
  result = test(path, env)
  context == :list ? [Scalar.new(result)] : result
rescue SystemCallError
  context == :list ? [Scalar.new('')] : ''
end