Rails: Passing Variables from a Class Method to an Instance Method -


I have several models that are a matter of concern. Each model passes in a hash, which means that they handle small differences using anxiety. I pass the hash through a class method like this:

  add_update_to: group ,: user   

is the full code of concern: Module Updateable ActiveSupport Expand: Expand Attr_accessor: Stream Module ClassMethods def add_updates_to (* stream) @ streams = streams end end module InstanceMethods def update_streams @ streams.collect {| Stream | Self.public_send (stream)} has been included at the end: Update, as: = & gt; : Updatable after_create: create_update_and_history end personal def create_update_and_history update = self.create_update (: user_id = & gt; User.current.id) self.update_streams.each do | Stream | Stream.histories.create (: update_id => update.id) End ending

Most of the code works, but I have to pass a hash from class to an example The problem is happening. At the moment, I am trying to make this effect a virtual characteristic, pass a hash to the attribute, and then try to recover it in the example. It just does not seem to be hackney, it does not work. I'm assuming that this does not work because @streams is a variable variable, so class method add_update_to can not actually set it?

Whatever the case, is there a better way to deal with this problem?

You can probably use square variables here, but there are quite untrained nature of those people in the Ruby community. They are condemned because of The thing to remember is that Ruby's classes are actually examples of classrooms, and may have their own example variables which are available only for themselves, and do not have access to their examples (if it is clear in any way ).

In this case, you are defining behavior , and not data , so I think neither the examples and square variables are appropriate. Instead, I think that your best bet is to define the example methods directly within the class method:

  Modules Updateable ActiveSupport Expand: Anxiety module ClassMethods def add_updates_to (* stream ) Define_method: stream update_streams. Collegiate | Stream | Public_send (stream)} End end end   

BTW, there is no crowd involved, so I'm not sure what you were talking about. * Currents collects your argument in an array.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -