class Person def name; @name; end end class Employee < Person def name; "#{@name}, #{@title}"; end end class Letter # address letter to recipient's name without title def recipient_name super_name = Person.instance_method(:name) bound_name = super_name.bind(@recipient) bound_name.call end end
class Person def name; @name; end end class Employee < Person def name; "#{@name}, #{@title}"; end end class Letter # address letter to recipient's name without title def recipient_name super_name = Person.instance_method(:name) bound_name = super_name.bind(@recipient) bound_name.call end end
def scope if @product if current_api_user.has_spree_role?("admin") unless params[:show_deleted] variants = @product.variants_including_master else variants = @product.variants_including_master_and_deleted end else variants = @product.variants_including_master end else variants = Variant.scoped if current_api_user.has_spree_role?("admin") unless params[:show_deleted] variants = Variant.active end end end variants end
def scope if @product if current_api_user.has_spree_role?("admin") unless params[:show_deleted] variants = @product.variants_including_master else variants = @product.variants_including_master_and_deleted end else variants = @product.variants_including_master end else variants = Variant.scoped if current_api_user.has_spree_role?("admin") unless params[:show_deleted] variants = Variant.active end end end variants end
class Variant class << self alias_method :variants_including_master_and_deleted, :scoped alias_method :variants_including_master, :active end end def scope scoper = @product || Variant if current_api_user.has_spree_role?("admin") && params[:show_deleted] scoper.variants_including_master_and_deleted else scoper.variants_including_master end end