Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#each_filename

() { (::String) -> untyped } -> nil
() -> ::Enumerator[::String, nil]
each_filename {|component| ... } → nil
each_filename → new_enumerator

With a block given, yields each component of the string path:

Example
Pathname('/foo/bar/baz').each_filename {|filename| p filename }
=> nil

Output:

"foo"
"bar"
"baz"

With no block given, returns a new Enumerator.

See also #each_entry #each_line #each_child #empty? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0