Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 0 additions & 17 deletions recipe.rb

This file was deleted.

10 changes: 0 additions & 10 deletions student.rb

This file was deleted.

28 changes: 28 additions & 0 deletions train.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
train_info = {}
train_info[:City] = 'Austin' #keys => #value
Copy link
Member

Choose a reason for hiding this comment

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

mostly, keys like this would be lowercase, like :city

There's nothing wrong with it -- in fact, you can have numbers, strings, objects, classes, anything as your hash keys. But for readability, I'd go with lowercase :city

train_info[:Engines] = 2
train_info[:Cars] = 5
train_info[:Caboose] = 1

train = {} #nested hash
train[:train_info] = train_info
puts "Train"

train[:train_info].each do |key, value|
puts "* #{key}: #{value}"
end

Passenger = Struct.new(:train, :names)
passenger = Passenger.new( train[:train_info] , ['Harry'] )

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

puts "\nNames"
passenger.names.each do |name|
puts "#{name}"
end