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
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
Alle Friday 15 February 2008, Luca S. ha scritto:
Cheers
LuCa
p(@var == “v” ? “V” : “M”)
Stefano
Luca S. wrote:
@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.
Alle Friday 15 February 2008, Sebastian H. ha scritto:
Luca S. wrote:
@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.
And put brackets around the arguments of p, otherwise you’ll get a
syntax
error
Stefano
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 ?
Stefano C. wrote:
Alle Friday 15 February 2008, Sebastian H. ha scritto:
Luca S. wrote:
@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.
And put brackets around the arguments of p, otherwise you’ll get a
syntax
errorStefano
Alle Friday 15 February 2008, Luca S. 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs