Re: #to_b - why isn't this one already in there?
- From: Robert Klemme <shortcutter@xxxxxxxxxxxxxx>
- Date: Sat, 08 Sep 2007 17:53:06 +0200
On 08.09.2007 16:42, Lloyd Linklater wrote:
Phlip wrote:Michael T. Richter wrote:
Si.sorry? I don't know what you mean.if foo == "false"In which locales?
can see the usefulness of this.
I think he was trying to gently point out that "false" is English, so it's likely to be the kind of problem only an English speaker would have. (Not that I can say I've ever had this problem of confusing false with "false" in *ANY* language.
This seems a bit silly to me. The language of Ruby is far more English than any other language.
I am not sure: Ruby originated in Japan and has a strong Japanese community AFAIK. You may not have notice because Matz, Nobu and all the others are kind enough to use English when they post here. :-)
Would this be of any use:
"false" == false.to_s
I'm not sure what you try to point out. If you are referring to the fact that false returns "false" when invoking #to_s (which is locale unaware) then I'd say this is a different story: one string representation *has* to be chosen and what would be more natural than using the same wording?
Conversion of values obtained from user input or something similar is a completely different story because these will usually be in a particular language which often depends on the user. Note that, if I'm not mistaken, browsers can send anything for marked checkboxes and radiobuttons in forms so the proper distinction might rather be present and not present. (Dunno how Rails handles this though).
Another note: I am increasingly reluctant to modify core classes to achieve specialized behavior like this. A simple method called on the result of the Hash lookup would have served the same purpose. An even more efficient solution would use a Hash for conversion:
# one variant
BOOL = Hash.new {|h,k| k}.merge("false" => false)
Kind regards
robert
.
- References:
- #to_b - why isn't this one already in there?
- From: Giles Bowkett
- Re: #to_b - why isn't this one already in there?
- From: Phlip
- Re: #to_b - why isn't this one already in there?
- From: Giles Bowkett
- Re: #to_b - why isn't this one already in there?
- From: Phlip
- Re: #to_b - why isn't this one already in there?
- From: Lloyd Linklater
- #to_b - why isn't this one already in there?
- Prev by Date: Re: new to ruby
- Next by Date: Re: wishing of reactive programming in ruby
- Previous by thread: Re: #to_b - why isn't this one already in there?
- Next by thread: Re: #to_b - why isn't this one already in there?
- Index(es):