Ruby 2.4.0 リファレンスマニュアル > ライブラリ一覧 > pathnameライブラリ > Pathnameクラス > basename

instance method Pathname#basename

basename(suffix = "") -> Pathname[permalink][rdoc]

Pathname.new(File.basename(self.to_s, suffix)) と同じです。

[PARAM] suffix:
サフィックスを文字列で与えます。'.*' という文字列を与えた場合、'*' はワイルドカードとして働き '.' を含まない任意の文字列にマッチします。


require "pathname"

Pathname("ruby/ruby.c").basename          #=> #<Pathname:"ruby.c">
Pathname("ruby/ruby.c").basename(".c")    #=> #<Pathname:"ruby">
Pathname("ruby/ruby.c").basename(".*")    #=> #<Pathname:"ruby">
Pathname("ruby/ruby.exe").basename(".*")  #=> #<Pathname:"ruby">
Pathname("ruby/y.tab.c").basename(".*")   #=> #<Pathname:"y.tab">

[SEE_ALSO] File.basename