What am I missing about this? I have an expression, which looks to me to be true, but it still evaluates to false. Here''s the code: def self.get_stars_from_id_array( ids, ruleset_id ) templates = Array.new ids.each do |i| star = find( i ) logger.info star.ruleset_id logger.info ruleset_id if star.ruleset_id == ruleset_id then templates.push star end end templates end Logger output is 1 1 And yet, star.ruleset_id = ruleset_id always evaluates to false. This is in my model code. What''s going on here? Thanks! Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris <cpeters.email-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What am I missing about this? I have an expression, which looks to me > to be true, but it still evaluates to false. Here''s the code: > > def self.get_stars_from_id_array( ids, ruleset_id ) > templates = Array.new > ids.each do |i| > star = find( i ) > logger.info star.ruleset_id > logger.info ruleset_id > if star.ruleset_id == ruleset_id then > templates.push star > end > end > templates > end > > Logger output is > 1 > 1 > > And yet, star.ruleset_id = ruleset_id always evaluates to false. This > is in my model code. What''s going on here?If one is a string, and the other is an integer, that will evaluate to false; irb(main):001:0> a = "1" => "1" irb(main):002:0> b = 1 => 1 irb(main):003:0> a == b => false irb(main):004:0> a.to_i == b.to_i => true Cheers, Tyler --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris wrote:> What am I missing about this? I have an expression, which looks to me > to be true, but it still evaluates to false. Here''s the code: > > def self.get_stars_from_id_array( ids, ruleset_id ) > templates = Array.new > ids.each do |i| > star = find( i ) > logger.info star.ruleset_id > logger.info ruleset_id > if star.ruleset_id == ruleset_id then > templates.push star > end > end > templates > end > > Logger output is > 1 > 1 > > And yet, star.ruleset_id = ruleset_id always evaluates to false. This > is in my model code. What''s going on here?I''m betting that one is a string and one is an integer. Try: logger.info star.ruleset_id.inspect logger.info ruleset_id.inspect Pete Yandell http://notahat.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---