Overriding a parent method and making it private/protected
I'm trying to make the create
method private/protected for an ActiveRecord
model. I want to do something like this:
class Product < ActiveRecord::Base
def self.create(options)
private
super(options)
end
end
so that I am unable to do Product.create(...)
. However, I need to do this
class Pencil < Product
def self.cre开发者_C百科ate(options)
options["category"] = "stationary"
super(options)
end
end
so that I can do this Pencil.create(...)
. Thanks in advance!
class Product < ActiveRecord::Base
class << self
def create(options)
super(options)
end
private :create
end
end
class Pencil < Product
class << self
def create(options)
options["category"] = "stationary"
super(options)
end
end
end
精彩评论