Hi all
I''m a bit unsure about the caching with ||= ...
I have the following code
class Member < ActiveRecord::Base
  def allowed_to?(right, model)
    # Setup owned system rights if not already done
    unless @owned_system_rights
      setup_owned_system_rights
    else
      raise "asdf"
    end
    ...
  end
  private
  def setup_owned_system_rights
    @owned_system_rights = {}
    system_groups.each do |system_group|
      system_group.system_rights.each do |system_right|
        @owned_system_rights[system_right.model_class.to_sym] = {}
unless @owned_system_rights[system_right.model_class.to_sym]
       
@owned_system_rights[system_right.model_class.to_sym][system_right.name.to_sym]
= true
      end
    end
  end
end
I''d expect the raise "asdf" to be reached some time, but
it''s not.
What''s wrong here?
Thanks, Josh
-- 
Posted via http://www.ruby-forum.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
-~----------~----~----~----~------~----~------~--~---
On 3 Nov 2007, at 21:28, Joshua Muheim wrote:> > Hi all > > I''m a bit unsure about the caching with ||= ... > > I have the following code > > class Member < ActiveRecord::Base > def allowed_to?(right, model) > > # Setup owned system rights if not already done > unless @owned_system_rights > setup_owned_system_rights > else > raise "asdf" > end > ... > endThis cache is instance specific - if you''re not calling allowed_to more than once per instance of member per action then I woudn''t expect that line to be reached. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh, I found the error, thanks. :-) -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---