Skip to content

Commit 4f158f5

Browse files
nobuparacycle
authored andcommitted
[DOC] The order of command line options
1 parent bc752a4 commit 4f158f5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

doc/language/options.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ $ basename `pwd`
129129
ruby
130130
```
131131

132+
This option is accumulative; relative paths are solved from the
133+
previous working directory.
134+
135+
```console
136+
$ ruby -C / -C usr -e 'puts Dir.pwd'
137+
/usr
138+
```
139+
140+
If the argument is not an existing directory, a fatal error will
141+
occur:
142+
143+
```console
144+
$ ruby -C /nonexistent
145+
ruby: Can't chdir to /nonexistent (fatal)
146+
$ ruby -C /dev/null
147+
ruby: Can't chdir to /dev/null (fatal)
148+
```
149+
132150
Whitespace between the option and its argument may be omitted.
133151

134152
### `-d`: Set `$DEBUG` to `true`
@@ -273,6 +291,16 @@ $ ruby -I my_lib -I some_lib -e 'p $LOAD_PATH.take(2)'
273291
$ popd
274292
```
275293

294+
This option and {option `-C`}[rdoc-ref:@-C+Set+Working+Directory] will
295+
be applied in the order in the command line; expansion of `-I` options
296+
are affected by preceeding `-C` options.
297+
298+
```console
299+
$ ruby -C / -Ilib -C usr -Ilib -e 'puts $:[0, 2]'
300+
/lib
301+
/usr/lib
302+
```
303+
276304
Whitespace between the option and its argument may be omitted.
277305

278306
### `-l`: Set Output Record Separator; Chop Lines
@@ -396,6 +424,11 @@ $ ruby -r csv -r json -e 'p defined?(JSON); p defined?(CSV)'
396424
"constant"
397425
```
398426

427+
The library is loaded with the `Kernel#require` method, after the
428+
other options such as {`-C`}[rdoc-ref:@-C+Set+Working+Directory],
429+
{`-I`}[rdoc-ref:@-I+Add+to+LOADPATH], and "custom options" by
430+
{`-s`}[rdoc-ref:@-s+Define+Global+Variable], are applied:
431+
399432
Whitespace between the option and its argument may be omitted.
400433

401434
### `-s`: Define Global Variable

0 commit comments

Comments
 (0)