I'm just wondering if there's something similar in Ruby or RnR?
This post: Why no tail() or head() method in List to get last or first element? talks about this about Java but I'm wondering the same thing but in Ruby or RnR.
Thanks for yr time!
Ruby on Rails is an open-source web development framework, which provides Ruby developers a timesaving alternative to develop code.
Ruby | Array class first() function first() is a Array class method which returns the first element of the array or the first 'n' elements from the array.
Rails is a web application development framework written in the Ruby programming language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks.
Here is one possiblity:
head, *tail = args
It uses the Ruby splat operator.
Example:
args = [1, 2, 3, 4, 5, 6, 7, 8]
# => [1, 2, 3, 4, 5, 6, 7, 8]
head, *tail = args
head
# => 1
tail
# => [2, 3, 4, 5, 6, 7, 8]
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