diff options
| author | Alexander Momchilov <amomchilov@users.noreply.github.com> | 2024-12-12 20:49:45 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-12 17:49:45 -0800 |
| commit | 0ea5c13bc6c4707aa8d2dce9b0c5af7513fb5f66 (patch) | |
| tree | ab1268590d5ede477433b8e222af040e0887e131 /doc/ruby | |
| parent | beff3e1272b227cf08b8670abeba5b60b58ddfcd (diff) | |
[DOC] Improve formatting in Markdown files (#12322)
* Fix WASM bullet/code indentation
* Use `console` code highlighting where appropriate
… which handles the prefix `$` correctly.
* Migrate feature proposal template to MarkDown
* Set language on code blocks
Diffstat (limited to 'doc/ruby')
| -rw-r--r-- | doc/ruby/option_dump.md | 8 | ||||
| -rw-r--r-- | doc/ruby/options.md | 65 |
2 files changed, 37 insertions, 36 deletions
diff --git a/doc/ruby/option_dump.md b/doc/ruby/option_dump.md index 00d0ec77d5..5324c335d0 100644 --- a/doc/ruby/option_dump.md +++ b/doc/ruby/option_dump.md @@ -5,7 +5,7 @@ see {Option --dump}[options_md.html#label--dump-3A+Dump+Items]. For the examples here, we use this program: -```sh +```console $ cat t.rb puts 'Foo' ``` @@ -26,7 +26,7 @@ The supported dump items: - `parsetree`: {Abstract syntax tree}[https://en.wikipedia.org/wiki/Abstract_syntax_tree] (AST): - ```sh + ```console $ ruby --dump=parsetree t.rb ########################################################### ## Do NOT use this node dump for any purpose other than ## @@ -52,7 +52,7 @@ The supported dump items: - `parsetree_with_comment`: AST with comments: - ```sh + ```console $ ruby --dump=parsetree_with_comment t.rb ########################################################### ## Do NOT use this node dump for any purpose other than ## @@ -89,7 +89,7 @@ The supported dump items: - `yydebug`: Debugging information from yacc parser generator: - ```sh + ``` $ ruby --dump=yydebug t.rb Starting parse Entering state 0 diff --git a/doc/ruby/options.md b/doc/ruby/options.md index 143c8925f1..6e0278e143 100644 --- a/doc/ruby/options.md +++ b/doc/ruby/options.md @@ -5,13 +5,13 @@ Some examples here use command-line option `-e`, which passes the Ruby code to be executed on the command line itself: -```sh +```console $ ruby -e 'puts "Hello, World."' ``` Some examples here assume that file `desiderata.txt` exists: -``` +```console $ cat desiderata.txt Go placidly amid the noise and the haste, and remember what peace there may be in silence. @@ -44,7 +44,7 @@ argument values: Examples: -```sh +```console $ ruby -0 -e 'p $/' "\x00" ruby -00 -e 'p $/' @@ -77,7 +77,7 @@ See also: Option `-a`, when given with either of options `-n` or `-p`, splits the string at `$_` into an array of strings at `$F`: -```sh +```console $ ruby -an -e 'p $F' desiderata.txt ["Go", "placidly", "amid", "the", "noise", "and", "the", "haste,"] ["and", "remember", "what", "peace", "there", "may", "be", "in", "silence."] @@ -107,7 +107,7 @@ See also: Option `-c` specifies that the specified Ruby program should be checked for syntax, but not actually executed: -``` +```console $ ruby -e 'puts "Foo"' Foo $ ruby -c -e 'puts "Foo"' @@ -120,7 +120,7 @@ The argument to option `-C` specifies a working directory for the invoked Ruby program; does not change the working directory for the current process: -```sh +```console $ basename `pwd` ruby $ ruby -C lib -e 'puts File.basename(Dir.pwd)' @@ -140,7 +140,7 @@ these commonly write to `$stdout` or `$stderr`. The default value for `$DEBUG` is `false`; option `-d` sets it to `true`: -```sh +```console $ ruby -e 'p $DEBUG' false $ ruby -d -e 'p $DEBUG' @@ -154,7 +154,7 @@ Option `--debug` is an alias for option `-d`. Option `-e` requires an argument, which is Ruby code to be executed; the option may be given more than once: -``` +```console $ ruby -e 'puts "Foo"' -e 'puts "Bar"' Foo Bar @@ -170,7 +170,7 @@ but should not include arguments (which, if given, are ignored). Option `-E` requires an argument, which specifies either the default external encoding, or both the default external and internal encodings for the invoked Ruby program: -``` +```console # No option -E. $ ruby -e 'p [Encoding::default_external, Encoding::default_internal]' [#<Encoding:UTF-8>, nil] @@ -198,7 +198,7 @@ Option `--encoding` is an alias for option `-E`. Option `-F`, when given with option `-a`, specifies that its argument is to be the input field separator to be used for splitting: -```sh +```console $ ruby -an -Fs -e 'p $F' desiderata.txt ["Go placidly amid the noi", "e and the ha", "te,\n"] ["and remember what peace there may be in ", "ilence.\n"] @@ -208,7 +208,7 @@ $ ruby -an -Fs -e 'p $F' desiderata.txt The argument may be a regular expression: -``` +```console $ ruby -an -F'[.,]\s*' -e 'p $F' desiderata.txt ["Go placidly amid the noise and the haste"] ["and remember what peace there may be in silence"] @@ -247,7 +247,7 @@ For a longer help message, use option `--help`. Option `-i` sets the \ARGF in-place mode for the invoked Ruby program; see ARGF#inplace_mode=: -``` +```console $ ruby -e 'p ARGF.inplace_mode' nil $ ruby -i -e 'p ARGF.inplace_mode' @@ -262,7 +262,7 @@ The argument to option `-I` specifies a directory to be added to the array in global variable `$LOAD_PATH`; the option may be given more than once: -```sh +```console $ pushd /tmp $ ruby -e 'p $LOAD_PATH.size' 8 @@ -287,7 +287,7 @@ modifies line-ending processing by: Without option `-l` (unchopped): -```sh +```console $ ruby -n -e 'p $_' desiderata.txt "Go placidly amid the noise and the haste,\n" "and remember what peace there may be in silence.\n" @@ -297,7 +297,7 @@ $ ruby -n -e 'p $_' desiderata.txt With option `-l' (chopped): -```sh +```console $ ruby -ln -e 'p $_' desiderata.txt "Go placidly amid the noise and the haste," "and remember what peace there may be in silence." @@ -320,9 +320,9 @@ See also: ### `-n`: Run Program in `gets` Loop -Option `-n` runs your program in a Kernel#gets loop: +Option `-n` runs your program in a `Kernel#gets` loop: -``` +```ruby while gets # Your Ruby code. end @@ -331,7 +331,7 @@ end Note that `gets` reads the next line and sets global variable `$_` to the last read line: -```sh +```console $ ruby -n -e 'puts $_' desiderata.txt Go placidly amid the noise and the haste, and remember what peace there may be in silence. @@ -356,7 +356,7 @@ See also: Option `-p` is like option `-n`, but also prints each line: -```sh +```console $ ruby -p -e 'puts $_.size' desiderata.txt 42 Go placidly amid the noise and the haste, @@ -387,7 +387,7 @@ The argument to option `-r` specifies a library to be required before executing the Ruby program; the option may be given more than once: -```sh +```console $ ruby -e 'p defined?(JSON); p defined?(CSV)' nil nil @@ -413,7 +413,7 @@ in the invoked Ruby program: More than one custom option may be given: -``` +```console $ cat t.rb p [$foo, $bar] $ ruby t.rb @@ -439,7 +439,7 @@ the program is executed in the shell's current working directory This example uses adds path `'tmp/'` to the `PATH` environment variable: -```sh +```console $ export PATH=/tmp:$PATH $ echo "puts File.basename(Dir.pwd)" > /tmp/t.rb $ ruby -S t.rb @@ -450,7 +450,7 @@ ruby Options `-v` prints the Ruby version and sets global variable `$VERBOSE`: -``` +```console $ ruby -e 'p $VERBOSE' false $ ruby -v -e 'p $VERBOSE' @@ -482,7 +482,7 @@ by setting the initial value of global variable `$-W`: The value of `$-W`, in turn, determines which warning messages (if any) are to be printed to `$stdout` (see Kernel#warn): -```sh +```console $ ruby -W1 -e 'p $foo' nil $ ruby -W2 -e 'p $foo' @@ -493,14 +493,15 @@ nil Ruby code may also define warnings for certain categories; these are the default settings for the defined categories: -``` +```rb Warning[:experimental] # => true Warning[:deprecated] # => false Warning[:performance] # => false ``` They may also be set: -``` + +```rb Warning[:experimental] = false Warning[:deprecated] = true Warning[:performance] = true @@ -508,7 +509,7 @@ Warning[:performance] = true You can suppress a category by prefixing `no-` to the category name: -``` +```console $ ruby -W:no-experimental -e 'p IO::Buffer.new' #<IO::Buffer> ``` @@ -529,7 +530,7 @@ The ruby code: Example: -```sh +```console $ cat t.txt Leading garbage. #!ruby @@ -545,7 +546,7 @@ The optional argument specifies the directory where the text file is to be found; the Ruby code is executed in that directory: -```sh +```console $ cp t.txt /tmp/ $ ruby -x/tmp t.txt tmp @@ -567,7 +568,7 @@ See Thread::Backtrace.limit. Option `--copyright` prints a copyright message: -```sh +```console $ ruby --copyright ruby - Copyright (C) 1993-2024 Yukihiro Matsumoto ``` @@ -642,7 +643,7 @@ sets the default external encoding for the invoked Ruby program; for values of +encoding+, see {Encoding: Names and Aliases}[rdoc-ref:encodings.rdoc@Names+and+Aliases]. -```sh +```console $ ruby -e 'puts Encoding::default_external' UTF-8 $ ruby --external-encoding=cesu-8 -e 'puts Encoding::default_external' @@ -664,7 +665,7 @@ sets the default internal encoding for the invoked Ruby program; for values of +encoding+, see {Encoding: Names and Aliases}[rdoc-ref:encodings.rdoc@Names+and+Aliases]. -```sh +```console $ ruby -e 'puts Encoding::default_internal.nil?' true $ ruby --internal-encoding=cesu-8 -e 'puts Encoding::default_internal' |
