Skip to content

Conversation

@robskrob
Copy link

I'm not too sure if I understood the instructions correctly or where you were trying to go with:
passengers = [Passenger.new(name: 'Bill Smith'), Passenger.new(name: 'Sarah Robot')]
Train.new( passengers, {destination: 'New York', number_of_engines: 4, caboose: true, number_of_cars: 5})

train.rb Outdated
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

@robskrob
Copy link
Author

Here's my second attempt

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants