I created a Model class where I define methods based on a method (attribute) called in User (which inherits from Model). The problem is that I cannot override the method defined by define_method and call super to jump to the specific method. I assume that this is due to the fact that a certain method is added to the user himself, and not to the model, so in fact he does not have a method in the superclass (i.e. in the model).
The reason I want to do this is because most attributes must be stored directly in the database, and some attributes, such as a password, need additional processing.
class Model
def self.attribute(name)
define_method(name) do
self
end
end
end
class User < Model
attribute :password
end
class User2 < Model
attribute :password
def password
super
end
end
@user = User.new
puts @user.password
@user2 = User2.new
puts @user2.password
, ? .