Ruby Dir Class and Methods
Dir is a directory stream that represents the file names in a directory in the operating system. The Dir class also has operations related to directories, such as wildcard file name matching, changing the working directory, and so on.
Class Methods
| No. | Method & Description |
|---|---|
| 1 | **Dir[pat] |
Dir::glob( pat)**
Returns an array containing file names that match the specified wildcard pattern pat:
- * - Matches any string, including the null string
- ** - Recursively matches any string
- ? - Matches any single character
- [...] - Matches any one of the enclosed characters
- {a,b...} - Matches any one of the characters in the string
Instance Methods
Assume d Is Dir An instance of the class:
| No. | Method & Description |
|---|---|
| 1 | d.close |
| Closes the directory stream. | |
| 2 | d.each {| f| ...} |
| Executes the block once for each entry in d. | |
| 3 | d.pos |
d.tell
返回 d 中的当前位置。 |
| 4 | d.pos= offset
Sets the position in the directory stream. | | 5 | d.pos= pos
d.seek(pos)
Moves to a certain position in d. pos must be a value returned by d.pos or 0. | | 6 | d.read
Returns the next entry in d. | | 7 | d.rewind
Moves the position in d to the first entry. | | 8 | d.seek(po s)
See d.pos=pos. | | 9 | d.tell
See d.pos. |