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
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 978
def join(*args)
return self if args.empty?
result = args.pop
result = Pathname.new(result) unless Pathname === result
return result if result.absolute?
args.reverse_each {|arg|
arg = Pathname.new(arg) unless Pathname === arg
result = arg + result
return result if result.absolute?
}
self + result
end
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>
See also
#has_trailing_separator?
#lchmod
#grpowned?
#lchown
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0