RubyoffRails/recipe-hash — pull request #22 by timsvoice (2014-05-12 19:48:35+00:00)
Title: created train Struct

I have a question:
I followed the recipe.rb pattern, but instead of placing an array (am I right in thinking the [ ] signify an array?), I wanted just a single passenger name. But puts "#{value}" output was blank.

This is the code I tried:

train = {}
train[:city] = "Johannesburg"
train[:engines] = 2
train[:cars] = 10
train[:caboose] = true

Passenger = Struct.new(:train, :name)

passenger = Passenger.new( {city: "New York", engines: 2, cars: 10, caboose: true}, "Timothy Voice")

puts "Train"
passenger.train.each do |key, value|
puts "* #{key}: #{value}"
end

puts "\nPassenger"
passenger.name do |value|
puts "#{value}"
end