On 02/01/2011 10:33 PM, Kamarulnizam R. wrote:
@@convert_yaml = nil
if @@convert_yaml.nil? then
@@convert_yaml = YAML::load_file(‘nizam.yaml’)
Given the way you used this class within the EnergyManagement class,
there is no need to make EnergyManagement inherit from Environmental.
the input of my yaml file is similar as data within the dashed line. The
thing is, by eliminating the brackets as i mentioned earlier will
eliminate the double dashes (- - name: Efficiency (Energy)), hence
corrected the indentation on my yaml output file. I just dnt know how to
eliminate that bracket since i added two hashes (‘objective’ and ‘mon’)
into an array (‘tar’).
Let’s fix some terminology here just to prevent potential confusion.
You don’t want to eliminate brackets. You want to extract these items
from the array in which they are embedded. “Eliminating brackets” is
something you would do directly to the string output generated by
something like the inspect method. The apparent extra array is the root
of the problem rather than the brackets shown when you inspect it.
- type: ContentBox
OK. It’s really hard to be sure here, but I think the problem is that
you need to convert this section of your code:
The issue is that tar is an array of hashes, but it appears that you
actually want to append the contents of tar to the data structure you
have from the YAML file instead of appending tar itself. This code
appends the contents of the array in tar to the existing array in that
mess of hashes.
There are other ways to handle this, but this one is the simplest
change. The downside is that you would prevent someone actually
appending tar as-is if they actually wanted to do so. Maybe that’s not
an issue for this code.