Hey chaps,
Is is at all possible to have a statement such as
p "some string " if ( stuff || more_stuff || other_stuff)
–
Regards,
John M.
Hey chaps,
Is is at all possible to have a statement such as
p "some string " if ( stuff || more_stuff || other_stuff)
–
Regards,
John M.
John M. wrote:
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>
On Sat, 2008-02-09 at 09:28 +0900, John M. wrote:
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
On 09.02.2008 01:36, Tim H. wrote:
You don’t have to ask. Try it yourself. Start up irb and enter a statement:
=> nil
irb(main):005:0>
And you can spare the brackets
irb(main):001:0> “yes” if false || false || true
=> “yes”
Cheers
robert
Oh sorry, forgot to have a look on the senders, thought you were the one
who started this thread.
On [Sat, 09.02.2008 09:39], fw wrote:
I’m not sure what I’m missing here:
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.
|| operator return true if at least one of the operands is true, so:
false || false || true returns true, and hello is printed.
false || false returns false and thus, nothing is printed (nil).
Note: || operator stops evaluating when the first true yielding
expression is found.
On Fri, 8 Feb 2008 19:39:06 -0500, fw [email protected]
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