Prev | Current Page 102 | Next

Brad Ediger

"Advanced Rails"

rb, core_ext/integer/inflections.rb
??? Integer#multiple_of?(number), Integer#even?, and Integer#odd? test for divisibility.
3.even? # => false
3.odd? # => true
3.multiple_of? 3 # => true
??? Integer#ordinalize converts an integer to an ordinal number.
puts (1..10).map {|i| i.ordinalize}.to_sentence
# >> 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, and 10th
Kernel
Daemonize core_ext/kernel/daemonizing.rb
Normally, when a process is attached to a console and that console exits, the program
terminates. Kernel#daemonize is used to detach a Ruby process from the console, allowing it
to persist even if the console goes away. A typical daemon process will use daemonize as in
the following example:
# server setup; process options
daemonize # detach from tty
loop do
# wait for request
# process request
end
Sending SIGTERM to a daemonized process kills it.
Reporting core_ext/kernel/reporting.rb
The top-level methods in this file control console messages that might be displayed.
??? silence_warnings turns warnings off for the duration of the block. enable_warnings
turns warnings on for the duration of the block.
??? silence_stream(stream) silences the given stream (usually STDOUT or STDERR) for the
duration of the block.
??? suppress(*exception_classes) ignores errors of the specified classes during the execution
of the block.
Module
70 | Chapter 2: ActiveSupport and RailTies
Module
Aliasing core_ext/module/aliasing.


Pages:
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114