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#join

(*::String | ::_ToStr | ::Pathname args) -> ::Pathname
join(*components) → self or new_pathname

With no arguments, returns self.

With arguments, joins the given components to the string path in self with character '/'; returns a new pathname containing the joined string:

Example
pn = Pathname('foo')                      # => #<Pathname:foo>
# String arguments.
pn.join('bar')                            # => #<Pathname:foo/bar>
pn.join(*%w[bar baz bat])                 # => #<Pathname:foo/bar/baz/bat>
# Pathname arguments.
pn.join(Pathname('bar'), Pathname('baz')) # => #<Pathname:foo/bar/baz>