Hi guys. I''m experiencing some strange behaviour in my Rails app. I have a constant, and two class methods: #----------# COORDINATES_NOT_NULL_SQL ''latitude IS NOT NULL and longitude IS NOT NULL'' def self.sql_for_non_null_coordinates COORDINATES_NOT_NULL_SQL end def self.filtered_properties(params) conditions_string = self.sql_for_non_null_coordinates ...8<... conditions_string << '' AND '' << filtered[:sql] ...8<... end #----------# If I call #filtered_properties multiple times in a row, the value that #sql_for_non_null_coordinates returns changes: http://pastie.org/299037 This line is causing the change: conditions_string = self.sql_for_non_null_coordinates But why? And is it possible to prevent this behaviour? Thanks, Nick --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 23, 1:30 pm, "Kazim Zaidi" <pursui...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Nick, > This is because Ruby constants are not constants. They can change. > Ruby warns you when you reinitialize a constant, but not otherwise. > That is, > Constant << "anything" > won''t produce a warning. > > You should use something like, > conditions_string = self.sql_for_non_null_coordinates.dup > ....Thanks for the tip, Kazim! That answers my question perfectly. Cheers, Nick --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---