[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

meaning of %w

Junkone

7/1/2008 8:51:00 AM

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

Ryan Davis

7/1/2008 9:09:00 AM

0


On Jul 1, 2008, at 01:52 , Junkone wrote:

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

%w doesn't have to do with sprintf afaik.

Maybe you mean this instead:

http://www.zenspider.com/Languages/Ruby/QuickR...


Junkone

7/1/2008 9:22:00 AM

0

On Jul 1, 5:08 am, Ryan Davis <ryand-r...@zenspider.com> wrote:
> On Jul 1, 2008, at 01:52 , Junkone wrote:
>
> > what is the meaning of %w. atlest in my copy of rubydoc, i could not
> > find the w attribute in sprintf flag characters
>
> %w doesn't have to do with sprintf afaik.
>
> Maybe you mean this instead:
>
> http://www.zenspider.com/Languages/Ruby/QuickR...

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.

Frederick Cheung

7/1/2008 9:28:00 AM

0


On 1 Jul 2008, at 10:22, Junkone wrote:

> On Jul 1, 5:08 am, Ryan Davis <ryand-r...@zenspider.com> wrote:
>> On Jul 1, 2008, at 01:52 , Junkone wrote:
>>
>>> what is the meaning of %w. atlest in my copy of rubydoc, i could not
>>> find the w attribute in sprintf flag characters
>>
>> %w doesn't have to do with sprintf afaik.
>>
>> Maybe you mean this instead:
>>
>> http://www.zenspider.com/Languages/Ruby/QuickR...
>
> 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

Peña, Botp

7/1/2008 9:28:00 AM

0

From: Junkone [mailto:junkone1@gmail.com]=20
# what is the meaning of %w. atlest in my copy of rubydoc, i could not
# find the w attribute in sprintf flag characters

we may need a site search for ruby-doc, otherwise, nubies like me will =
have to look harder ;)

look for references to "array" in this page =
http://www.ruby-doc.org/docs/ProgrammingRuby/html/lan.... you =
wont miss it.

hth. kind regards -botp





Peña, Botp

7/1/2008 9:37:00 AM

0

From: Junkone [mailto:junkone1@gmail.com]=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

Junkone

7/1/2008 10:06:00 AM

0

On Jul 1, 5:36 am, Peña, Botp <b...@delmonte-phil.com> wrote:
> From: Junkone [mailto:junko...@gmail.com]
> # 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.