I am reading data from an XML file then converting the data from Strings to integers, but when I try to process the data, Ruby is claiming the objects are of type String. Which doesn’t make sense to me because I convert all of the elements to type integer.
#converts the string data array to an integer array
def self.barify_data(data)
data.each{ |i| i.to_i() }
end
data = BarChart.barify_data(data)
data.each {|d| puts d.class }
This outputs:
String
String
String
String
String
String
String
String
String
String
String
String
String
Can anyone tell me why the conversion isnt happening?
Thanks.
The #each method runs the block for every element, but returns the original element.
You’re probably looking for #map