Reputation: 2202
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!
Upvotes: 54
Views: 42142
Reputation: 122
irb(main):001:0> [1,2,3,4,5].slice! 0,4
=> [1, 2, 3, 4]
Just another way to do it.
Upvotes: 8
Reputation: 51166
The Array#take method is probably what you want.
['one','two','three'].take(2)
Upvotes: 115
Reputation: 17793
You have Array#first:
['one','two','three'].first(2)
=> ['one', 'two']
Upvotes: 41