maeshimaの日記

メモ書きです

pathname

RubyPulse :: RubyPulse Episode 0.40 - pathname - Pathname represents a pathname which locates a file in a filesystem. - RubyDocをみて。

pathnameはpathnameを簡単に扱える標準ライブラリ。

require File.join(File.dirname(__FILE__), 'boot')

みたいな煩雑になりがちなパスの扱いを楽にしてくれるみたい。

利用例

require 'pathname'
path = Pathname.new("/hoge/fuga")
path.parent #=> /hoge

また、File, FileTest, Dir, IO, FileUtilsクラスのメソッドのラッパーでもあるみたい。

rails

Rails 2.3.8 で確認

  • RAILS_ROOT => String
  • Rails.root => Pathname オブジェクト