Skip to content
Open
Changes from 3 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
40 changes: 40 additions & 0 deletions train.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Passenger = Struct.new(:name)
Train = Struct.new(:destination, :number_of_cars, :caboose, :number_of_engine)

passengers = [Passenger.new(name: 'Bill Smith'), Passenger.new(name: 'Sarah Robot')]
train = Train.new( passengers, {destination: 'New York', number_of_engines: 4, caboose: true, number_of_cars: 5})

puts "Destination: #{train.destination}"
puts "Cars: #{train.number_of_cars}"
puts "Caboose: #{train.caboose}"
puts "Passengers: #{passengers}"
Copy link
Member

Choose a reason for hiding this comment

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

what does this output? Is it what you would expect?

Copy link
Author

Choose a reason for hiding this comment

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

Everything works except: puts "Engines: #{train.number_of_engines}"

Copy link
Author

Choose a reason for hiding this comment

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

The output is the following:
$ ruby train.rb
Destination: [#<struct Passenger name={:name=>"Bill Smith"}>, #<struct Passenger name={:name=>"Sarah Robot"}>]
Cars: {:destination=>"New York", :number_of_engines=>4, :caboose=>true, :number_of_cars=>5}
Caboose:
Passengers: [#<struct Passenger name={:name=>"Bill Smith"}>, #<struct Passenger name={:name=>"Sarah Robot"}>]
train.rb:11:in <main>': undefined methodnumber_of_engines' for #Train:0x007fb9311a86b8 (NoMethodError)

Copy link
Member

Choose a reason for hiding this comment

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

So, the destination seems wrong, as well as Cars, Caboose, and Passengers.

If your definition for train is Struct.new(:destination, :number_of_cars, :caboose, :number_of_engine) then what are you sending in?

Train = Struct.new(:destination, :number_of_cars, :caboose, :number_of_engine)

There isn't a place for passengers.

And to simplify things, let's change

train = Train.new( passengers, {destination: 'New York', number_of_engines: 4, caboose: true, number_of_cars: 5})

to

train = Train.new( passengers, 'New York', 4, true, 5)

Copy link
Author

Choose a reason for hiding this comment

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

perhaps I should watch the video again...it is not clear to me what should
be a hash vs a Struct and how to construct it the way you want it. I will
start over again.

On Tue, Jan 14, 2014 at 12:46 PM, Jesse Wolgamott
notifications@github.comwrote:

In train.rb:

@@ -0,0 +1,40 @@
+Passenger = Struct.new(:name)
+Train = Struct.new(:destination, :number_of_cars, :caboose, :number_of_engine)
+
+passengers = [Passenger.new(name: 'Bill Smith'), Passenger.new(name: 'Sarah Robot')]
+train = Train.new( passengers, {destination: 'New York', number_of_engines: 4, caboose: true, number_of_cars: 5})
+
+puts "Destination: #{train.destination}"
+puts "Cars: #{train.number_of_cars}"
+puts "Caboose: #{train.caboose}"
+puts "Passengers: #{passengers}"

So, the destination seems wrong, as well as Cars, Caboose, and Passengers.

If your definition for train is Struct.new(:destination, :number_of_cars,
:caboose, :number_of_engine) then what are you sending in?

Train = Struct.new(:destination, :number_of_cars, :caboose, :number_of_engine)

There isn't a place for passengers.

And to simplify things, let's change

train = Train.new( passengers, {destination: 'New York', number_of_engines: 4, caboose: true, number_of_cars: 5})

to

train = Train.new( passengers, 'New York', 4, true, 5)


Reply to this email directly or view it on GitHubhttps://github.com//pull/14/files#r8868170
.

Robert Jewell
1.914.400.5219

puts "Engines: #{train.number_of_engines}"



=begin
puts 'train specifications:'
description.each do |key, value|
puts "#{key}: #{value}"
end

puts 'train destination:'
destination.each do |key, value|
puts "#{key}: #{value}"
end

puts 'Passenger\'s name'
bill.name.each do |key, value|
puts "#{key}: #{value}"
end

puts 'Bill\'s destination'
bill.destination.each do |key, value|
puts "#{key}: #{value}"
end

puts 'Bill\'s train specifications'
bill.description.each do |key, value|
puts "#{key}: #{value}"
end
=end