开发者

test(?e, ARGV[0])

开发者 https://www.devze.com 2023-02-22 09:10 出处:网络
What is the test function in the next Ruby expression: unless ARGV.size == 1 and t开发者_运维百科est(?e, ARGV[0])

What is the test function in the next Ruby expression:

unless ARGV.size == 1 and t开发者_运维百科est(?e, ARGV[0])


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消