I am looking into someones code and found that he has done class eval with something like this
self.class_eval("@default_robot_engine = RobotEngine.new(some_block)")
and later it is accessed like this
self.class_eval("@default_robot_engine")
I need help to understand this code. Is there any other way to access @default_robot_engine rather than doing class_eval on it?
when I do Class.instance_variable_names I get
["@attribute_methods_mutex", "@generated_attribute_methods", "@generated_feature_methods", "@observer_instances", "@per_page", "@parent_name", "@registered_robot_engines", "@default_robot_engine", "@primary_key", "@quoted_primary_key", "@locking_column", "@attribute_methods_generated", "@table_name", "@quoted_table_name", "@arel_table", "@arel_engine", "@relation", "@columns", "@column_names", "@columns_hash", "@cached_attributes", "@attribute_method_matchers_cache", "@generated_external_attribute_methods"]
and I am able to access all the instance variable like this ClassName.registered_robot_engine
except default_robot_engine
. why?
Ok I got the answer because this instance variable is a dynamic one and attr_reader is not set on it so I think only way to access it is via class_eval