K
Kamarulnizam Rahim
Hi guys,
I have a problem inheriting data from the parent class to its
subclasses. My code is as followed:
class Environmental
def initialize
convert_yaml = YAML::load_file('nizam.yaml')
end
def display
#convert_yaml = YAML::load_file('nizam.yaml')
end
end
class EnergyManagement < Environmental
def initialize(title)
@title = title
end
def display
#convert_yaml = YAML::load_file('nizam.yaml')
convert_yaml["System"]["Environmental"]["children"][2]["children"]
<< @title
File.open("nizam_out.yaml", "w"){|f| YAML.dump(convert_yaml, f)}
end
end
class WasteManagement < Environmental
def initialize(title)
@title = title
end
def display
#convert_yaml = YAML::load_file('nizam.yaml')
convert_yaml["System"]["Environmental"]["children"][3]["children"]
<< @title
File.open("nizam_out.yaml", "w"){|f| YAML.dump(convert_yaml, f)}
end
end
I want to use 'convert_yaml' for its subclasses (EnergyManagement and
WasteManagement) but when i run my code, 'convert_yaml' is not
recognized in the subclasses.
undefined local variable or method `convert_yaml' for
#<EnergyManagement:0x261d0b0> (NameError)
The reason i use this inheritance is because i want to write on the same
yaml file if both subclasses were called. Before this, i use
convert_yaml on every subclass but i found out that the yaml output
("nizam_out.yaml") file was overwritten if i call both subclasses at the
same time. Sorry if my explanation quite confusing as i do not know how
to explain this more clearly. Any help would be great. Thanks in
advance.
Nizam
I have a problem inheriting data from the parent class to its
subclasses. My code is as followed:
class Environmental
def initialize
convert_yaml = YAML::load_file('nizam.yaml')
end
def display
#convert_yaml = YAML::load_file('nizam.yaml')
end
end
class EnergyManagement < Environmental
def initialize(title)
@title = title
end
def display
#convert_yaml = YAML::load_file('nizam.yaml')
convert_yaml["System"]["Environmental"]["children"][2]["children"]
<< @title
File.open("nizam_out.yaml", "w"){|f| YAML.dump(convert_yaml, f)}
end
end
class WasteManagement < Environmental
def initialize(title)
@title = title
end
def display
#convert_yaml = YAML::load_file('nizam.yaml')
convert_yaml["System"]["Environmental"]["children"][3]["children"]
<< @title
File.open("nizam_out.yaml", "w"){|f| YAML.dump(convert_yaml, f)}
end
end
I want to use 'convert_yaml' for its subclasses (EnergyManagement and
WasteManagement) but when i run my code, 'convert_yaml' is not
recognized in the subclasses.
undefined local variable or method `convert_yaml' for
#<EnergyManagement:0x261d0b0> (NameError)
The reason i use this inheritance is because i want to write on the same
yaml file if both subclasses were called. Before this, i use
convert_yaml on every subclass but i found out that the yaml output
("nizam_out.yaml") file was overwritten if i call both subclasses at the
same time. Sorry if my explanation quite confusing as i do not know how
to explain this more clearly. Any help would be great. Thanks in
advance.
Nizam