Method: Array#to
- Defined in:
- activesupport/lib/active_support/core_ext/array/access.rb
#to(position) ⇒ Object
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) # => []
24 25 26 27 28 29 30 |
# File 'activesupport/lib/active_support/core_ext/array/access.rb', line 24 def to(position) if position >= 0 take position + 1 else self[0..position] end end |