Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions train.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
train = {}
train[:current_city] = 'New York'
train[:number_of_engines] = 4
train[:number_of_cars] = 8
train[:caboose] = true

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

passenger = Passenger.new('Bill Smith') #(current_city: 'New York', number_of_engines: 4, number_of_cars: 8, caboose: true, name: 'Bill Smith')
passenger.train = train

puts "Train Specifications:"
passenger.train.each do |key, value|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Robert --

I don't want you to use the key,value interface of Struct. I'm trying to get you to use the dot syntax, as an object, from a Struct. It's a way to easily pass around an object -- the receiver that you pass to, won't know it's a struct.

puts "#{key}: #{value}"
end

puts "Passenger Name:"
passenger[:name] = 'Bill Smith'
puts passenger.name


#Passenger = Struct.new