I have a class like this:
class MyClass
class << self
attr_accessor :user, :password, :port, :ssl, :host
end
@user=“pepe”
@password=""
@port=345
@ssl=true
end
So I can use later for example:
MyClass.port
That’s good for me… but now i need to create another one that is
inhering from this one… for example:
class MyOtherClass < MyClass; end
and now when i do something like:
MyOtherClass.port
what i get is nil instead of 345
Technically You can’t use this method in case of inheritance because
instance variables which was defined at the class level belongs only to
the object of this class. Thus in Your case all instance variables
belongs to the MyClass object, but not to any child object of the class.
One case to resolve it, I suppose is use ActiveSupport::Configurable
module in such manner:
require ‘active_support/configurable’
class MyClass
include ActiveSupport::Configurable