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 hash and passenger struct #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions passenger2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def name
name = "Lori"
end

def city
city = "New York"
Copy link
Member

Choose a reason for hiding this comment

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

In ruby, you don't need to have "city = " here. if you wanted to have method that returns "New York", you should:

def city
  "New York"
end

More likely, you really wanted to do this (outside of a method)

city = "New York"

Copy link
Author

Choose a reason for hiding this comment

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

Thanks...fixed them .. but on trying a pull request:
Pull request creation failed. Validation failed: A pull request already exists for lorio:master.
but they do work fine. Will move on.

On Aug 26, 2013, at 5:00 PM, Jesse Wolgamott [email protected] wrote:

In passenger2.rb:

@@ -0,0 +1,15 @@
+def name

  • name = "Lori"
    +end

+def city

  • city = "New York"
    In ruby, you don't need to have "city = " here. if you wanted to have method that returns "New York", you should:

def city
"New York"
end
More likely, you really wanted to do this (outside of a method)

city = "New York"

Reply to this email directly or view it on GitHub.

Copy link
Member

Choose a reason for hiding this comment

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

GitHub pulls automatically update when you push to the branch you originally created on. So I see the changes you made.

end

Passenger = Struct.new(:city, :name)

lori = Passenger.new

puts "Passenger: #{name}, #{city}"
Copy link
Member

Choose a reason for hiding this comment

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

I think here you wanted to do this instead:

puts "Passenger: #{lori.name}, #{lori.city}"



16 changes: 16 additions & 0 deletions train.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
train = {}
train[:city] = "New York"
train[:engines] = 1
train[:cars] = 6

train_parts = {}
train_parts[:train] = train

puts "Train:"
train_parts[:train].each do |key, value|
puts " * #{key}: #{value}"
end

puts " * and a caboose."