Today I Learned

hashrocket A Hashrocket project

Ruby Array slice shortcut

Today I learned that Ruby has an alias for Array slice method, basically you can use the [] the same way you'd use the slice method:

array = [ "a", "b", "c", "d", "e" ]

array[3..5]
# => ["d", "e"]

array.slice(3..5)
# => ["d", "e"]
See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.