values_at

ary.values_at(selector, ...) â new_ary
Instance Public methods

Returns an array containing the elements in self corresponding to the given selector(s).

The selectors may be either integer indices or ranges.

See also #select.

a = %w{ a b c d e f }
a.values_at(1, 3, 5)          # => ["b", "d", "f"]
a.values_at(1, 3, 5, 7)       # => ["b", "d", "f", nil]
a.values_at(-1, -2, -2, -7)   # => ["f", "e", "e", nil]
a.values_at(4..6, 3...6)      # => ["e", "f", nil, "d", "e", "f"]
doc_ruby_on_rails
2015-03-30 21:25:06
Comments
Leave a Comment

Please login to continue.