Skip to content

Commit a7361d3

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Harmonize chmod methods doc
1 parent 25ab32c commit a7361d3

2 files changed

Lines changed: 59 additions & 50 deletions

File tree

file.c

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,26 +2946,28 @@ chmod_internal(const char *path, void *mode)
29462946

29472947
/*
29482948
* call-seq:
2949-
* File.chmod(mode, *paths) -> integer
2949+
* File.chmod(mode, *paths) -> integer
29502950
*
2951-
* Changes the mode (i.e., permissions) of the entries of each the given +paths+;
2952-
* see {File Permissions}[rdoc-ref:File@File+Permissions].
2953-
* Returns the count of the given +paths+:
2951+
* Changes the modes of each of the entries at each the given +paths+;
2952+
* returns the count of the given +paths+.
2953+
* See {Filesystem Modes}[rdoc-ref:file/filesystem_modes.md]
2954+
* and especially {Setting a Mode}[rdoc-ref:file/filesystem_modes.md@Setting+a+Mode].
29542955
*
2955-
* filepath = 't.tmp'
2956-
* File.write(filepath, 'foo')
2957-
* dirpath = 'tempdir'
2958-
* Dir.mkdir(dirpath)
2959-
* File::Stat.new(filepath).mode.to_s(8) # => "100664"
2960-
* File::Stat.new(dirpath).mode.to_s(8) # => "40775"
2961-
* File.chmod(0775, filepath, dirpath) # => 2
2962-
* File::Stat.new(filepath).mode.to_s(8) # => "100775"
2963-
* File::Stat.new(dirpath).mode.to_s(8) # => "40775"
2964-
* File.chmod(0664, filepath, dirpath) # => 2
2965-
* File::Stat.new(filepath).mode.to_s(8) # => "100664"
2966-
* File::Stat.new(dirpath).mode.to_s(8) # => "40664"
2967-
* File.delete(filepath)
2968-
* Dir.rmdir(dirpath)
2956+
* These examples use
2957+
* a {helper method}[rdoc-ref:file/filesystem_modes.md@Helper+Method], +mode+,
2958+
* that displays a mode both in octal digits and in characters:
2959+
*
2960+
* dirpath = 'doc/foo'
2961+
* filepath = File.join(dirpath, 't.tmp')
2962+
* Dir.mkdir(dirpath) # Create directory.
2963+
* mode(dirpath) # => "040775 drwxrwxr-x"
2964+
* File.write(filepath, 'bar') # Create file.
2965+
* mode(filepath) # => "100664 -rw-rw-r--"
2966+
* File.chmod(0755, filepath) # Change file mode.
2967+
* mode(filepath) # => "100755 -rwxr-xr-x"
2968+
* File.chmod(0664, dirpath) # Change directory mode.
2969+
* mode(dirpath) # => "040664 drw-rw-r--"
2970+
* FileUtils.rm_rf(dirpath) # Clean up.
29692971
*
29702972
*/
29712973

@@ -3005,15 +3007,25 @@ rb_fchmod(struct rb_io* io, mode_t mode)
30053007

30063008
/*
30073009
* call-seq:
3008-
* file.chmod(mode_int) -> 0
3010+
* chmod(mode) -> 0
3011+
*
3012+
* Changes the mode of +self+; returns '0'.
3013+
* See {Filesystem Modes}[rdoc-ref:file/filesystem_modes.md]
3014+
* and especially {Setting a Mode}[rdoc-ref:file/filesystem_modes.md@Setting+a+Mode].
30093015
*
3010-
* Changes permission bits on <i>file</i> to the bit pattern
3011-
* represented by <i>mode_int</i>. Actual effects are platform
3012-
* dependent; on Unix systems, see <code>chmod(2)</code> for details.
3013-
* Follows symbolic links. Also see File#lchmod.
3016+
* These examples use
3017+
* a {helper method}[rdoc-ref:file/filesystem_modes.md@Helper+Method], +mode+,
3018+
* that displays a mode both in octal digits and in characters:
3019+
*
3020+
* filepath = 'doc/t.tmp'
3021+
* File.write(filepath, 'foo')
3022+
* file = File.new(filepath)
3023+
* mode(filepath) # => "100664 -rw-rw-r--"
3024+
* file.chmod(0775)
3025+
* mode(filepath) # => "100775 -rwxrwxr-x"
3026+
* file.close
3027+
* File.delete(filepath)
30143028
*
3015-
* f = File.new("out", "w");
3016-
* f.chmod(0644) #=> 0
30173029
*/
30183030

30193031
static VALUE

pathname_builtin.rb

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,31 +1503,28 @@ def mtime() File.mtime(@path) end
15031503
# call-seq:
15041504
# chmod(mode) -> 1
15051505
#
1506-
# Changes the mode (i.e., permissions) of the entry represented by `self`;
1507-
# see {File Permissions}[rdoc-ref:File@File+Permissions]:
1508-
#
1509-
# ```ruby
1510-
# # Pathname for a (non-existent) directory.
1511-
# dir_pn = Pathname('doc/foo') # => #<Pathname:doc/foo>
1512-
# # Create the directory and fetch its mode.
1513-
# dir_pn.mkdir
1514-
# dir_pn.stat.mode.to_s(8) # => "40775"
1515-
# # Change the directory mode and fetch the new mode.
1516-
# dir_pn.chmod(0777)
1517-
# dir_pn.stat.mode.to_s(8) # => "40777"
1518-
#
1519-
# # Pathname for a (non-existent) file in the directory.
1520-
# file_pn = dir_pn.join('t.tmp') # => #<Pathname:doc/foo/t.tmp>
1521-
# # Create the file and fetch its mode.
1522-
# file_pn.write('foo')
1523-
# file_pn.stat.mode.to_s(8) # => "100664"
1524-
# # Change the file mode and fetch its new mode.
1525-
# file_pn.chmod(0777)
1526-
# file_pn.stat.mode.to_s(8) # => "100777"
1527-
#
1528-
# # Clean up.
1529-
# file_pn.delete
1530-
# dir_pn.rmdir
1506+
# Changes the mode of the entry at the path in `self`; returns `1`.
1507+
# See {Filesystem Modes}[rdoc-ref:file/filesystem_modes.md]
1508+
# and especially {Setting a Mode}[rdoc-ref:file/filesystem_modes.md@Setting+a+Mode].
1509+
#
1510+
# These examples use
1511+
# a {helper method}[rdoc-ref:file/filesystem_modes.md@Helper+Method], `mode`,
1512+
# that displays a mode both in octal digits and in characters:
1513+
#
1514+
# ```ruby
1515+
# dirpath = 'doc/foo'
1516+
# dir_pn = Pathname(dirpath)
1517+
# dir_pn.mkdir # Create directory.
1518+
# mode(dirpath) # => "040775 drwxrwxr-x"
1519+
# filepath = File.join(dirpath, 't.tmp')
1520+
# file_pn = Pathname(filepath)
1521+
# file_pn.write('bar') # Create file.
1522+
# mode(filepath) # => "100664 -rw-rw-r--"
1523+
# file_pn.chmod(0755) # Change file mode.
1524+
# mode(filepath) # => "100755 -rwxr-xr-x"
1525+
# dir_pn.chmod(0644) # Change directory mode.
1526+
# mode(dirpath) # => "040644 drw-r--r--"
1527+
# dir_pn.rmtree # Clean up.
15311528
# ```
15321529
#
15331530
def chmod(mode) File.chmod(mode, @path) end

0 commit comments

Comments
 (0)