If || statements

J

John Maclean

Hey chaps,

Is is at all possible to have a statement such as

p "some string " if ( stuff || more_stuff || other_stuff)
 
T

Tim Hunter

John said:
Hey chaps,

Is is at all possible to have a statement such as

p "some string " if ( stuff || more_stuff || other_stuff)

You don't have to ask. Try it yourself. Start up irb and enter a statement:

$ irb
irb(main):001:0> x = 2
=> 2
irb(main):002:0> y = 3
=> 3
irb(main):003:0> z = "a"
=> "a"
irb(main):004:0> p "some string" if (x || y || z)
"some string"
=> nil
irb(main):005:0>
 
F

fw

Hey chaps,

Is is at all possible to have a statement such as

p "some string " if ( stuff || more_stuff || other_stuff)

I'm not sure what I'm missing here:

$ irb
irb(main):001:0> p "hello" if (false || false || true)
"hello"
=> nil
irb(main):002:0> p "hello" if (false || false)
=> nil


HTH,

Felix
 
R

Robert Klemme

You don't have to ask. Try it yourself. Start up irb and enter a statement:

$ irb
irb(main):001:0> x = 2
=> 2
irb(main):002:0> y = 3
=> 3
irb(main):003:0> z = "a"
=> "a"
irb(main):004:0> p "some string" if (x || y || z)
"some string"
=> nil
irb(main):005:0>

And you can spare the brackets

irb(main):001:0> "yes" if false || false || true
=> "yes"

Cheers

robert
 
D

Dominik Honnef

I'm not sure what I'm missing here:

$ irb
irb(main):001:0> p "hello" if (false || false || true)
"hello"
=> nil
irb(main):002:0> p "hello" if (false || false)
=> nil


HTH,

Felix

Uhm, it's working just the way everybody would expect it to work?
false or false or true evaluates to true (if i have the choice i of course take the best one)
false or false is just false, as there's no way to pick true.
 
D

Dominik Honnef

Oh sorry, forgot to have a look on the senders, thought you were the one who started this thread.
 

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

Similar Threads


Members online

Forum statistics

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

Latest Threads

Top