P
Peer Allan
Hi,
I have building a small custom library and I want to be able to define a
constant in each subclass identifying "valid" options. Each subclass
will have its own list.
here is how I tried to do it, please ignore the literal values, this is
just an example:
class Base
def method(option)
raise MyException unless VALID.include?(option)
do_with_option(option)
end
end
class SubClassA < Base
VALID = ['color','size','weight']
end
class SubClass < Base
VALID = ['name','phone','email']
end
sub = SubClass.new
sub.option('phone')
This results in a "uninitialized constant VALID" error. Why is that?
It is like the VALID constant is not being recognized in the subclass.
I would appreciate any direction on how to best handle what I am looking
to do.
Thanks
Peer
I have building a small custom library and I want to be able to define a
constant in each subclass identifying "valid" options. Each subclass
will have its own list.
here is how I tried to do it, please ignore the literal values, this is
just an example:
class Base
def method(option)
raise MyException unless VALID.include?(option)
do_with_option(option)
end
end
class SubClassA < Base
VALID = ['color','size','weight']
end
class SubClass < Base
VALID = ['name','phone','email']
end
sub = SubClass.new
sub.option('phone')
This results in a "uninitialized constant VALID" error. Why is that?
It is like the VALID constant is not being recognized in the subclass.
I would appreciate any direction on how to best handle what I am looking
to do.
Thanks
Peer