-3

"true"? "Yes" : "No" , I am using ruby language

This is taking by deafult "yes" even I select "no"

David Thornley
  • 56,304
  • 9
  • 91
  • 158
user557657
  • 856
  • 1
  • 12
  • 35
  • 3
    Please provide _enormous_ amounts of detail. – SLaks Jan 26 '11 at 17:53
  • 2
    Edit your question to post the actual code, copy-pasted from your program. Also tell us what you are doing specifically, and what the exact results are. I'm editing tags to include "Ruby"; please use a language tag for future language-dependent questions. – David Thornley Jan 26 '11 at 17:55
  • I am using check box speak_english? == "true"? "Yes" : "No" but it always take no, is there something missing?? – user557657 Jan 26 '11 at 17:55
  • what check box?? check box to store a value (yes/no)... – user557657 Jan 26 '11 at 17:57
  • There are no check boxes in the ruby language. What you want is `rdf.speak_english? "Yes" : "No"` – adamax Jan 26 '11 at 18:31
  • Are you by chance using Rails and trying to get the value of a checkbox posted in a form? – zetetic Jan 26 '11 at 20:12

2 Answers2

2
value = condition ? value-if-true : value-if-false

is a shortcut for this

if condition == true
    value = value-if-true
else
    value = value-if-false

If you have a condition that is always evaluated as true, you will always have value-if-true. In the example code "true" is always a true expression. The only values which are treated as false in an expression are false and nil.

mgronber
  • 3,399
  • 16
  • 20
  • Eh, it would be more accurate to say it's a shortcut for `value = if condition then value_if_true else value_if_false; end` — normal ifs are expressions too in Ruby, and there are a lot of truthy values that aren't equal to true. For example: `1 ? "1 is truthy " + (1 == true ? "and equal to true" : "but not equal to true") : "One is not truthy"` – Chuck Jan 26 '11 at 18:07
1

It's a little hard to tell what you're taking, but the value "true" is a string. For the boolean value, you want just true, with no quotation marks.

Chuck
  • 234,037
  • 30
  • 302
  • 389