3 ms·
I saw one post mention File.world_readable? I don't know Ruby and the result surprised me. irb(main):002:0> File.world_readable?('/etc/passwd') => 420 i
by parfe 15y ago
I saw one post mention File.world_readable? I don't know Ruby and the result surprised me.
irb(main):002:0> File.world_readable?('/etc/passwd')
=> 420
irb(main):003:0> File.world_readable?('/etc/shadow')
=> nil
420 is decimal for octal 0644 which is the permissions on my /etc/passwd file. Fair enough, but as someone looking from the outside it seems weird to leak partial and unreliable information like that. Especially if I was to write
readable = File.world_readable?('/etc/passwd')
and later readable has an integer in it representing an octal value which can't be used for more than a true/false value. Is it common to throw !! in front of truthy/falsey calls to get down to the boolean literal?
- nfm 15y agoIt's not a common idiom to use !! in Ruby.