advance :months => 1 # => Sat Nov 24 23:50:11 -0600 2007
t.advance :years => 1 # => Fri Oct 24 23:50:11 -0500 2008
??? Convenient shorthand methods, listed below (all are instance methods of Time that
take no arguments):
??” last_year and next_year
??” last_month and next_month
??” beginning_of_week (aliased as monday and at_beginning_of_week) and next_week
??” beginning_of_day (aliased as midnight, at_midnight, and at_beginning_of_day) and
end_of_day
??” beginning_of_month (also at_beginning_of_month) and end_of_month (also at_end_
of_month)
??” beginning_of_quarter (at_beginning_of_quarter)
??” beginning_of_year (at_beginning_of_year)
??” yesterday, tomorrow
Enumerable core_ext/enumerable.rb
??? Enumerable#group_by groups the values into a hash based on the result of a block.
(1..5).to_a.group_by {|x| x%3} # => {0=>[3], 1=>[1, 4], 2=>[2, 5]}
??? Enumerable#index_by indexes values based on the result of a block. It differs from
group_by in that it only keeps one value per index key.
(1..5).to_a.index_by {|x| x%3} # => {0=>3, 1=>4, 2=>5}
??? Enumerable#sum returns the sum of the values (or the result of mapping the given block
over the values, if a block is given). The optional first argument provides a value to use
if the enumerable is empty.
(1..5).to_a.sum # => 15
(1..5).to_a.sum {|x| x ** 2} # => 55
This makes statistical calculations easy:
module Enumerable
def mean
(sum.
Pages:
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109