rb
??? Array#in_groups_of(size, fill_with) groups elements of an array into fixed-size groups:
(1..8).to_a.in_groups_of(3) # => [[1, 2, 3], [4, 5, 6], [7, 8, nil]]
(1..8).to_a.in_groups_of(3, 0) # => [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
(1..8).to_a.in_groups_of(3, false) # => [[1, 2, 3], [4, 5, 6], [7, 8]]
??? Array#split splits an array on a value or the result of a block:
(1..8).to_a.split(4) # => [[1, 2, 3], [5, 6, 7, 8]]
(1..8).to_a.split {|i| i == 2} # => [[1], [3, 4, 5, 6, 7, 8]]
Option processing core_ext/array/extract_options.rb
??? Array#extract_options! removes and returns the last array item if it is a hash; otherwise,
it returns an empty hash. This supports the common pattern of using a hash as
the last argument to provide keyword arguments to a method:
def example(*args)
options = args.extract_options!
"#{args.inspect} :: #{options.inspect}"
end
example 1 # => "[1] :: {}"
example 1, 2 # => "[1, 2] :: {}"
example 1, 2, :a => 3 # => "[1, 2] :: {:a=>3}"
Random selection core_ext/array/random_access.rb
??? Array#rand returns an element selected at random from the array:
(1..10).map{ (1..10).to_a.rand } # => [2, 7, 7, 7, 7, 1, 10, 10, 2, 5]
Blank
62 | Chapter 2: ActiveSupport and RailTies
Blank core_ext/blank.rb
ActiveSupport adds the blank? instance method to all objects. This method returns true for
the empty string, a string consisting only of whitespace, false, nil, [], or {}.
Pages:
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104