instance method
to
Ruby on Rails 4.2.9
Since v3.0.20Signature
to(position)
Returns the beginning of the array up to position.
%w( a b c d ).to(0) # => ["a"] %w( a b c d ).to(2) # => ["a", "b", "c"] %w( a b c d ).to(10) # => ["a", "b", "c", "d"] %w().to(0) # => [] %w( a b c d ).to(-2) # => ["a", "b", "c"] %w( a b c ).to(-10) # => []
Parameters
-
positionreq
Source
# File activesupport/lib/active_support/core_ext/array/access.rb, line 22
def to(position)
if position >= 0
first position + 1
else
self[0..position]
end
end
Defined in activesupport/lib/active_support/core_ext/array/access.rb line 22
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Array