LoginSignup
7
6

More than 5 years have passed since last update.

便利な Kernel#test の紹介です

Posted at

Kernel#test( cmd, file )

便利なcmdを紹介!他にも沢山あるので残りは Kernel#test( cmd, file ) で確認してください。
test.rb
file = "Gemfile"

# ?e:ファイルが存在する
test( ?e, file )  # => true

# ?z:ファイルサイズが 0 である
test( ?z, file )  # => false

# ?s:ファイルサイズが 0 でない (ファイルサイズを返す、0 ならば nil) -> Integer|nil
test( ?s, file )  # => 63

# ?f:ファイルが存在する & ファイルはプレーンファイルである
test( ?f, file )  # => true

# ?f:ファイルが存在する & ファイルはプレーンファイルである
test( ?f, "file" )  # => false

# ?d:ファイルが存在する & ファイルはディレクトリである
test( ?d, file )  # => false

# ?d:ファイルが存在する & ファイルはディレクトリである
test( ?d, "vendor" )  # => true

# ?M:ファイルの最終更新時刻を返す -> Time
test( ?M, file )  # => 2012-02-17 02:10:45 +0900

# ?A:ファイルの最終アクセス時刻を返す -> Time
test( ?A, file )  # => 2012-02-18 00:10:41 +0900

# ?C:ファイルの inode 変更時刻を返す -> Time
test( ?C, file )  # => 2012-02-17 13:19:43 +0900
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6