Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#chmod
(::Integer mode_int) -> ::Integer
chmod(mode) → 1
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 1527
def chmod(mode) File.chmod(mode, @path) end
Changes the mode of the entry at the path in self; returns 1. See Filesystem Modes and especially Setting a Mode.
These examples use a helper method, mode, that displays a mode both in octal digits and in characters:
Example
dirpath = 'doc/foo' dir_pn = Pathname(dirpath) dir_pn.mkdir # Create directory. mode(dirpath) # => "040775 drwxrwxr-x" filepath = File.join(dirpath, 't.tmp') file_pn = Pathname(filepath) file_pn.write('bar') # Create file. mode(filepath) # => "100664 -rw-rw-r--" file_pn.chmod(0755) # Change file mode. mode(filepath) # => "100755 -rwxr-xr-x" dir_pn.chmod(0644) # Change directory mode. mode(dirpath) # => "040644 drw-r--r--" dir_pn.rmtree # Clean up.