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!
The array. max() method in Ruby enables us to find the maximum value among elements of an array. It returns the element with the maximum value.
Use the min Method to Get Minimum Number in an Array in Ruby Calling min without an argument returns the minimum number ( element ) but returns the n-smallest numbers if argument "n" is passed to it.
slice() in Ruby? The array. slice() is a method in Ruby that is used to return a sub-array of an array. It does this either by giving the index of the element or by providing the index position and the range of elements to return.
The Array#take method is probably what you want.
['one','two','three'].take(2)
You have Array#first:
['one','two','three'].first(2) => ['one', 'two']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With