Skip to content

Conversation

@trinityXmontoya
Copy link

Two questions actually!
First is that you said at the end of the video we could ask you if we wondering why you prefer the class X < Struct syntax over X = Struct.new, I'd love to hear why!
Also, I wasn't sure what creating a passenger that has a train meant? I've been working with RoR for the past week and all I can think of is :train :belongs_to :person, I know I'm overcomplicating it so could you just explain a little more what you're asking? Thanks so much! (Also if the pull request comment section isn't the proper place for this just let me know where it should go in the future!)

@jwo
Copy link
Member

jwo commented Apr 4, 2014

About the Struct syntax:

When you use the inheritance syntax, you end up with what is known as an “anonymous class” when you inspect the classes inheritance chain.

Does this matter? Nah, not really. Is this pedantic? Most definitely.

So why do I CARE? Something you have to pick sides, and I choose non-anonymous-classes.

screenshot 3 21 14 9 48 am

@jwo
Copy link
Member

jwo commented Apr 4, 2014

Also, I wasn't sure what creating a passenger that has a train meant?

Really, it's defining the interface... so, if you have a passenger that has a train, all I mean is that the following is a valid "interface".

passenger.train

So, that means, in the context of this exercise, that you:

Train = Train.new(all,the,train,stuff)
Passenger = Struct.new(name, train)

train = Train.new(stuff,goes,here)
passenger = Passenger.new("Phil Jo", train)

passenger.train
=> train

Does that make anymore sense?

And this is the perfect place for these discussions. Alternatively, the mailing list.

Copy link
Member

Choose a reason for hiding this comment

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

that's a nice use of meta-programming. It'll come in handy later.

attribute.to_s.capitalize.gsub('_',' ')

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