ruby on rails - Open Spree::User class and add functions without losing existing functions -


i'd add vendor? method spree::user class.

spree::user defined in solidus gem rails app uses. don't want touch code rather open class , append methods in main rails app.

e.g: rails_root/app/models/spree/user.rb

module spree   class user < spree::base      include spree::usermethods      def vendor?       self.role_users.any? { |ru| ru.role.name == 'vendor' }     end    end     end 

this not include methods admin? present before created patch.

is there way can extend existing class without manually copying of it's methods manually?

create file under config/initializers directory:

# config/initializers/spree_user.rb  spree::user.class_eval   def vendor?     self.role_users.any? { |ru| ru.role.name == 'vendor' }   end end 

it add single method existing class.


Comments