syntax problem: @var=="v" ? { ... } : { ... }

L

Luca Scaljery

Hi All

I tried to print an "M" or "V" depending on the value of a variable,
like

@var = "v"
@var == "v" ? { p "V" } : { p "M" }

this however doesn't work, but I'm sure something like this can be done!
Any suggestions ?

Cheers
LuCa
 
S

Stefano Crocco

Alle Friday 15 February 2008, Luca Scaljery ha scritto:
Hi All

I tried to print an "M" or "V" depending on the value of a variable,
like

@var = "v"
@var == "v" ? { p "V" } : { p "M" }

this however doesn't work, but I'm sure something like this can be done!
Any suggestions ?

Cheers
LuCa

p(@var == "v" ? "V" : "M")

Stefano
 
S

Sebastian Hungerecker

Luca said:
@var = "v"
@var == "v" ? { p "V" } : { p "M" }

this however doesn't work, but I'm sure something like this can be done!
Any suggestions ?

Leave out the curlies.
 
S

Stefano Crocco

Alle Friday 15 February 2008, Sebastian Hungerecker ha scritto:
Leave out the curlies.

And put brackets around the arguments of p, otherwise you'll get a syntax
error

Stefano
 
L

Luca Scaljery

thnx, that works, but what if I want to do 2 or more actions/statements
for each options ?

@var == "v" ? P("V");do_something("V") : ......

suggestions ?
 
S

Stefano Crocco

Alle Friday 15 February 2008, Luca Scaljery ha scritto:
thnx, that works, but what if I want to do 2 or more actions/statements
for each options ?

@var == "v" ? P("V");do_something("V") : ......

suggestions ?

In this case, I'd use a standard if:

if @var == "v"
p "V"
do_something
else
do_something_else
end

Stefano
 

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

Forum statistics

Threads
474,283
Messages
2,571,407
Members
48,101
Latest member
LinetteDeg

Latest Threads

Top