# File lib/amazon.rb, line 97 def to_s(first_detail='productname') string = "" # get all attributes, minus the leading '@' vars = self.instance_variables.sort.map {|v| v[1..-1]} # find the longest attribute name longest = vars.sort { |a,b| b.length <=> a.length }[0].length # put the product name at the front of the list, if we have one vars.unshift(first_detail) if vars.delete(first_detail) # display the product's details vars.each do |iv| value = self.instance_variable_get("@#{iv}").inspect string << "%-#{longest}s = %s\n" % [iv, value] end string end