I have the following which works well:
def steps %w[hello billing confirmation] end steps.first
But I want to do this:
def step_title %w['Upload a photo' 'Billing Info' 'Confirmation Screen'] end steps.first
How does %w allow for that? I tried a google search but google is weak with these types of characters.
Thanks
%w[hello billing confirmation] is syntax sugar for ["hello", "billing", "confirmation"] . It tells Ruby to break up the input string into words, based on the whitespace, and to return an array of the words.
Ruby on Rails is used in all types of industries to build web apps and services. This includes applications like marketing websites, CMSs, eCommerce sites, and custom web applications. It's a popular web framework for startups because its ease of use makes for quick application development with small teams.
Ruby on Rails (sometimes RoR) is the most popular open-source web application framework. It's built with the Ruby programming language. You can use Rails to help you build applications, from simple to complex, there are no limits to what you can accomplish with Rails!
%w
creates an "array of words," and uses whitespace to separate each value. Since you want to separate on another value (in this case, whitespace outside sets of quotation marks), just use a standard array:
['Upload a photo', 'Billing Info', 'Confirmation Screen']
%w()
is a "word array" - the elements are delimited by spaces.
There are other % things:
%r()
is another way to write a regular expression.
%q()
is another way to write a single-quoted string (and can be multi-line, which is useful)
%Q()
gives a double-quoted string
%x()
is a shell command.
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