Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

train model, question! #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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.

puts "TRAIN INFO"
puts "-----------"
train.members.each do |attribute|
puts "#{attribute.to_s.capitalize.gsub('_',' ')} - #{train.send(attribute)}"
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