Ruby Array limit method
RubyArraysRuby Problem Overview
I want to limit an Array object. How is this possible with ruby
['one','two','three'].limit(2) => ['one','two']
Thanks for your quick help!
Ruby Solutions
Solution 1 - Ruby
The Array#take method is probably what you want.
['one','two','three'].take(2)
Solution 2 - Ruby
You have Array#first:
['one','two','three'].first(2)
=> ['one', 'two']
Solution 3 - Ruby
irb(main):001:0> [1,2,3,4,5].slice! 0,4
=> [1, 2, 3, 4]
Just another way to do it.