CTRL-C
sendsINT
("interrupt") signal. Ignores input and creates a new prompt.CTRL-D
sendsEOT
("end of transmission") signal. Exits.CTRL-Z
sendsTSTP
("terminal stop") signal. Nothing.CTRL-\
sendsQUIT
signal. Unknown. (Note: does not dump core like other processes.)exit
- OptParse
- Open3
- system()
- `cmd`
- Shell
- ARGV
- ARGF
- STDIN and
$stdin
- STDERR and
$stderr
- STDOUT and
$stdout
- exit
The $_
variable.
ruby -e 'puts $_ while STDIN.gets'
ruby -e 'STDIN.each_line { |l| puts l.upcase }'
ruby -ne 'puts $_.upcase'
ruby -pe '$_.upcase!'
- ObjectSpace
- Tracer
- pp
require "debug"
# rails
obj.try!(:foo)
# ruby 2.3.0
obj&.foo
numbers = [2, [3, [6]]]
six = numbers.fetch(1).fetch(1).fetch(0)
six = numbers.dig(1, 1, 0)
person = {
name: {
first_name: "A",
last_name: "Z"
}
}
first_name = person.fetch(:name).fetch(:first_name)
first_name = person.dig(:name, :first_name)
ruby [switches] [--] [programfile] [arguments]
-rlibrary require the library before executing your script
-e 'command' one line of script. Several -e's allowed.
ruby -run -e COMMAND [--] [OPTIONS]
Note: POSIX Utility Syntax Guideline 10:
Guideline 10: The argument "--" should be accepted as a delimiter
indicating the end of options. Any following
arguments should be treated as operands, even if they
begin with the '-' character. The "--" argument
should not be used as an option or as an operand.
ruby -run -e help [COMMAND]
ruby -run -e help
ruby -run -e httpd -- [OPTION] DocumentRoot
ruby -run -e httpd -- .
ruby -run -e httpd -- --port 8000 .