CBlair1986 wrote:
> Hi. What I'd like to do is to take a file like so:
> ---
> Apple
> Color: Red
> Peel: Yes
> Has Core: Yes
>
> Orange
> Color: Orange
> Peel: Yes
> Has Core: No
> ---
> and go through it, line by line, assigning the 'Apple' and 'Orange'
> lines to a name attribute on different hashes, and then using the name
> before the colons such as 'Color' and 'Peel' as keys for the respective
> values.

table = {}
ARGF.each { |line|  line.strip!
  next if line == ""
  fields = line.split( /: +/ )
  if fields.size == 1
    $fruit = fields.first
    table[$fruit] = {}
  else
    table[$fruit][fields.first] = fields.last
  end
}

p table