2

What is the test function in the next Ruby expression:

unless ARGV.size == 1 and test(?e, ARGV[0])
ceth
  • 44,198
  • 62
  • 180
  • 289

1 Answers1

5

test() seems to be reminiscent of the shell tests to see if files or directories exist, are readable, etc:

irb(main):011:0> test(?e,"/etc/passwd")  # e for exist
=> true
irb(main):012:0> test(?e,"/does/not/exist")
=> false
irb(main):014:0> test(?e,"/etc")
=> true
irb(main):015:0> test(?d, "/etc")        # d for directory
=> true
irb(main):016:0> test(?d, "/etc/passwd")
=> false
irb(main):017:0> test(?r, "/etc/passwd") # r for readable
=> true
irb(main):018:0> test(?w, "/etc/passwd") # w for writable
=> false

Full details are in the ri Kernel#test documentation.

sarnold
  • 102,305
  • 22
  • 181
  • 238