My method:
def scroll_images
images_all[1..images_all.length]
end
I don't like that I'm calling images_all
twice, just wondering if there's a good trick to call self
or something similar to make this a little cleaner.
You can get the same result in a clearer way using the Array#drop
method:
a = [1, 2, 3, 4]
a.drop(1)
# => [2, 3, 4]
Use -1
instead of the length:
def scroll_images
images_all[1..-1] # `-1`: the last element, `1..-1`: The second to the last.
end
Example:
a = [1, 2, 3, 4]
a[1..-1]
# => [2, 3, 4]
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