Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
1978 != 1978
Shandy Nantz
12/19/2008 10:27:00 PM
I have these years that I am trying to compare to see if they are equal
and when my code get to the right year in question where it is supposed
to equate to true, it doesn't. Here is my code:
<% 1900.upto(year) do |i| %>
<%= option_tag(i, i, @user.dobyear.to_s == i.to_s ? true : false) %>
<% end %>
When I do some 'puts' I get a condition where '1978' == '1978' and that
results in a false value and I can't figure out why. Why in Ruby does
this happen? Thansk,
-S
--
Posted via
http://www.ruby-...
.
3 Answers
David A. Black
12/19/2008 10:40:00 PM
0
Hi --
On Sat, 20 Dec 2008, Shandy Nantz wrote:
> I have these years that I am trying to compare to see if they are equal
> and when my code get to the right year in question where it is supposed
> to equate to true, it doesn't. Here is my code:
>
> <% 1900.upto(year) do |i| %>
> <%= option_tag(i, i, @user.dobyear.to_s == i.to_s ? true : false) %>
> <% end %>
An aside: == returns true or false, so you don't have to do the whole
? true : false thing.
> When I do some 'puts' I get a condition where '1978' == '1978' and that
> results in a false value and I can't figure out why. Why in Ruby does
> this happen? Thansk,
Are there spaces around @user.dobyear? I'm not sure what you mean
about puts, except that puts returns nil, but I'm not sure how that
fits in with your question.
David
--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training:
http://www.r...
Coming in 2009: The Well-Grounded Rubyist (
http://manning....
)
Shandy Nantz
12/19/2008 10:48:00 PM
0
David A. Black wrote:
> Hi --
>
> On Sat, 20 Dec 2008, Shandy Nantz wrote:
>
> An aside: == returns true or false, so you don't have to do the whole
> ? true : false thing.
>
>> When I do some 'puts' I get a condition where '1978' == '1978' and that
>> results in a false value and I can't figure out why. Why in Ruby does
>> this happen? Thansk,
>
> Are there spaces around @user.dobyear? I'm not sure what you mean
> about puts, except that puts returns nil, but I'm not sure how that
> fits in with your question.
>
>
> David
With 'puts' I just meant that I did some output statements to see if in
fact the values I was comparing were equal or not. As for the comparison
when I took out the true and false parts it worked, thanks,
-S
--
Posted via
http://www.ruby-...
.
Josef 'Jupp' Schugt
12/19/2008 11:00:00 PM
0
* Shandy Nantz, 2008-12-20, 07:27:
> I have these years that I am trying to compare to see if they are
> equal and when my code get to the right year in question where it is
> supposed to equate to true, it doesn't. Here is my code:
>
> <% 1900.upto(year) do |i| %>
> <%= option_tag(i, i, @user.dobyear.to_s == i.to_s ? true : false) %>
> <% end %>
>
> When I do some 'puts' I get a condition where '1978' == '1978' and
> that results in a false value and I can't figure out why. Why in Ruby
> does this happen?
It does not (checked). I suppose that the value of @user.dobyear only
looks as if it were '1978' while in fact it contains some non-print
character. Try 'p' to verify.
And consider removing the ternary operator abuse. It makes not too much
sense to have it results in true (false) if @user.dobyear.to_s ==
i.to_s is true (false); I think using the truth value proper is the
variant one should prefer.
Josef 'Jupp' Schugt
--
Blog:
http://penpen.gooda...
(n/a atm)
PGP key (id 6CC6574F):
http://wwwkeys.d...
Jabber -
http://www.j...
- contact information on request
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
1978 != 1978
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password