下一个Ruby表达式中的测试函数是什么:
unless ARGV.size == 1 and test(?e, ARGV[0])
答案 0 :(得分:5)
test()
似乎让人联想到shell测试,看看文件或目录是否存在,是否可读等等:
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
完整的详细信息在ri Kernel#test
文档中。