meaning of %w

J

Junkone

what is the meaning of %w. atlest in my copy of rubydoc, i could not
find the w attribute in sprintf flag characters
 
F

Frederick Cheung

in rails, this is how it create the options for select box.
<%= select:)rawdata, :symbol, %w{ AUD.USD-IDEALPRO-CASH EUR.GBP-
IDEALPRO-CASH EUR.JPY-IDEALPRO-CASH EUR.USD-IDEALPRO-CASH GBP.USD-
IDEALPRO-CASH USD.CAD-IDEALPRO-CASH USD.CHF-IDEALPRO-CASH }) %>

what does the %w signify.

Exactly what the link Ryan posted says. It creates an array by
splitting the string you give it.

Fred
 
P

Peña, Botp

From: Junkone [mailto:[email protected]]=20
# in rails, this is how it create the options for select box.
# <%=3D select:)rawdata, :symbol, %w{ AUD.USD-IDEALPRO-CASH EUR.GBP-
# IDEALPRO-CASH EUR.JPY-IDEALPRO-CASH EUR.USD-IDEALPRO-CASH GBP.USD-
# IDEALPRO-CASH USD.CAD-IDEALPRO-CASH USD.CHF-IDEALPRO-CASH }) %>
# what does the %w signify.

in ruby, i learn by reading ruby-doc, and do-ing it using irb ;)

a =3D %w{ AUD.USD-IDEALPRO-CASH EUR.GBP-IDEALPRO-CASH =
EUR.JPY-IDEALPRO-CASH EUR.USD-IDEALPRO-CASH GBP.USD-IDEALPRO-CASH =
USD.CAD-IDEALPRO-CASH USD.CHF-IDEALPRO-CASH }

a.class
#=3D> Array

p a
["AUD.USD-IDEALPRO-CASH", "EUR.GBP-IDEALPRO-CASH", =
"EUR.JPY-IDEALPRO-CASH", "EUR.USD-IDEALPRO-CASH", =
"GBP.USD-IDEALPRO-CASH", "USD.CAD-IDEALPRO-CASH", =
"USD.CHF-IDEALPRO-CASH"]

some more examples (note, i can change the delimiters)

a=3D%w[this is a test]
#=3D> ["this", "is", "a", "test"]

a=3D%w(1 2 3 4)
#=3D> ["1", "2", "3", "4"]

a=3D%w<my name is bot\ pena>
#=3D> ["my", "name", "is", "bot pena"]

kind regards -botp
 
J

Junkone

From: Junkone [mailto:[email protected]]
# in rails, this is how it create the options for select box.
# <%= select:)rawdata, :symbol, %w{ AUD.USD-IDEALPRO-CASH EUR.GBP-
# IDEALPRO-CASH EUR.JPY-IDEALPRO-CASH EUR.USD-IDEALPRO-CASH GBP.USD-
# IDEALPRO-CASH USD.CAD-IDEALPRO-CASH USD.CHF-IDEALPRO-CASH }) %>
# what does the %w signify.

in ruby, i learn by reading ruby-doc, and do-ing it using irb ;)

a = %w{ AUD.USD-IDEALPRO-CASH EUR.GBP-IDEALPRO-CASH EUR.JPY-IDEALPRO-CASH EUR.USD-IDEALPRO-CASH GBP.USD-IDEALPRO-CASH USD.CAD-IDEALPRO-CASH USD.CHF-IDEALPRO-CASH }

a.class
#=> Array

p a
["AUD.USD-IDEALPRO-CASH", "EUR.GBP-IDEALPRO-CASH", "EUR.JPY-IDEALPRO-CASH", "EUR.USD-IDEALPRO-CASH", "GBP.USD-IDEALPRO-CASH", "USD.CAD-IDEALPRO-CASH","USD.CHF-IDEALPRO-CASH"]

some more examples (note, i can change the delimiters)

a=%w[this is a test]
#=> ["this", "is", "a", "test"]

a=%w(1 2 3 4)
#=> ["1", "2", "3", "4"]

a=%w<my name is bot\ pena>
#=> ["my", "name", "is", "bot pena"]

kind regards -botp

aah. thanks a lot for showing a new way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top