|
11 | 11 | # Pathname.new('lib') # => #<Pathname:lib> |
12 | 12 | # Pathname.new('/usr/local/bin') # => #<Pathname:/usr/local/bin> |
13 | 13 | # |
| 14 | +# == About the Examples |
| 15 | +# |
| 16 | +# Many examples here use these variables: |
| 17 | +# |
| 18 | +# :include: doc/examples/files.rdoc |
| 19 | +# |
14 | 20 | # == Convenience Methods |
15 | 21 | # |
16 | 22 | # The class provides *all* functionality from class File and module FileTest, |
@@ -1040,8 +1046,63 @@ def each_line(...) # :yield: line |
1040 | 1046 | File.foreach(@path, ...) |
1041 | 1047 | end |
1042 | 1048 |
|
1043 | | - # See <tt>File.read</tt>. Returns all data from the file, or the first +N+ bytes |
1044 | | - # if specified. |
| 1049 | + # call-seq: |
| 1050 | + # read(length = nil, offset = 0, **opts) -> string or nil |
| 1051 | + # |
| 1052 | + # Reads and returns some or all of the content of the file |
| 1053 | + # whose path is <tt>self.to_s</tt>. |
| 1054 | + # |
| 1055 | + # With no arguments given, |
| 1056 | + # reads in text mode and returns the entire content of the file: |
| 1057 | + # |
| 1058 | + # Pathname.new('t.txt').read |
| 1059 | + # # => "First line\nSecond line\n\nFourth line\nFifth line\n" |
| 1060 | + # Pathname.new('t.ja').read |
| 1061 | + # # => "こんにちは" |
| 1062 | + # Pathname.new('t.dat').read |
| 1063 | + # # => "\xFE\xFF\x99\x90\x99\x91\x99\x92\x99\x93\x99\x94" |
| 1064 | + # |
| 1065 | + # On Windows, text mode can terminate reading and leave bytes in the file unread |
| 1066 | + # when encountering certain special bytes. |
| 1067 | + # Consider using #binread if all bytes in the file should be read. |
| 1068 | + # |
| 1069 | + # With argument +length+ given, returns +length+ bytes if available: |
| 1070 | + # |
| 1071 | + # Pathname.new('t.txt').read(7) |
| 1072 | + # # => "First l" |
| 1073 | + # Pathname.new('t.ja').read(7) |
| 1074 | + # # => "\xE3\x81\x93\xE3\x82\x93\xE3" |
| 1075 | + # Pathname.new('t.dat').read(7) |
| 1076 | + # # => "\xFE\xFF\x99\x90\x99\x91\x99" |
| 1077 | + # |
| 1078 | + # Returns all bytes if +length+ is larger than the files size: |
| 1079 | + # |
| 1080 | + # Pathname.new('t.txt').read(700) |
| 1081 | + # # => "First line\r\nSecond line\r\n\r\nFourth line\r\nFifth line\r\n" |
| 1082 | + # Pathname.new('t.ja').read(700) |
| 1083 | + # # => "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF" |
| 1084 | + # Pathname.new('t.dat').read(700) |
| 1085 | + # # => "\xFE\xFF\x99\x90\x99\x91\x99\x92\x99\x93\x99\x94" |
| 1086 | + # |
| 1087 | + # With arguments +length+ and +offset+ given, |
| 1088 | + # returns +length+ bytes if available, beginning at the given +offset+: |
| 1089 | + # |
| 1090 | + # Pathname.new('t.txt').read(10, 2) |
| 1091 | + # # => "rst line\r\n" |
| 1092 | + # Pathname.new('t.ja').read(10, 2) |
| 1093 | + # # => "\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1" |
| 1094 | + # Pathname.new('t.dat').read(10, 2) |
| 1095 | + # # => "\x99\x90\x99\x91\x99\x92\x99\x93\x99\x94" |
| 1096 | + # |
| 1097 | + # Returns +nil+ if +offset+ is past the end of the file: |
| 1098 | + # |
| 1099 | + # Pathname.new('t.txt').read(10, 200) # => nil |
| 1100 | + # |
| 1101 | + # Optional keyword arguments +opts+ specify: |
| 1102 | + # |
| 1103 | + # - {Open Options}[rdoc-ref:IO@Open+Options]. |
| 1104 | + # - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options]. |
| 1105 | + # |
1045 | 1106 | def read(...) File.read(@path, ...) end |
1046 | 1107 |
|
1047 | 1108 | # See <tt>File.binread</tt>. Returns all the bytes from the file, or the first +N+ |
|
0 commit comments