Skip to content

Conversation

var114
Copy link

@var114 var114 commented Aug 7, 2013

No description provided.

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

@jwo
Copy link
Member

jwo commented Aug 8, 2013

Interesting choice with the train_info being a hash. I was expecting more of a Struct, but the hash works well indeed -- especially later when you iterate over the key/values.

Well done!

@var114
Copy link
Author

var114 commented Aug 8, 2013

A struct felt ugly wait do you mean just passing in all the variables?

Passenger = Struct.new(:train, :names)
passenger = Passenger.new( {city 'Austin', engine 2, cars 5, caboose 1} , ['Harry'] )

Like this?
On Aug 7, 2013, at 7:04 PM, Jesse Wolgamott [email protected] wrote:

Interesting choice with the train_info being a hash. I was expecting more of a Struct, but the hash works well indeed -- especially later when you iterate over the key/values.

Well done!


Reply to this email directly or view it on GitHub.

@jwo
Copy link
Member

jwo commented Aug 8, 2013

Something like:

Train = Struct.new(:city :engine, :cars, :caboose)
Passenger = Struct.new(:train, :names)

train = Train.new('austin', 2, 5, 1)
passenger = Passenger.new(train, ['harry'])

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