Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
Kernel

Integer | 69

Integer core_ext/integer/even_odd.rb,core_ext/integer/inflections.rb



  • Integer#multiple_of?(number),Integer#even?, andInteger#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#daemonizeis used to detach a Ruby process from the console, allowing it
to persist even if the console goes away. A typical daemon process will usedaemonizeas in
the following example:


server setup; process options


daemonize # detach from tty

loop do
# wait for request
# process request
end

SendingSIGTERM 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_warningsturns 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 (usuallySTDOUTorSTDERR) for the
    duration of the block.

  • suppress(*exception_classes)ignores errors of the specified classes during the execu-
    tion of the block.

Free download pdf