Spaghetti Refactory
Home
About
Projects
Github
Monday, December 14, 2015
Literally the coolest way to build an array
One of
Ruby’s literal syntax shorthands
,
%i
essentially loops over each word, converts to a symbol and adds it to an array. For example:
%
i
(dog cat mouse)
# => [:dog, :cat, :mouse]
Caveat: This syntax was added in Ruby 2.0, so don’t go trying it in any previous version.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment