-
Notifications
You must be signed in to change notification settings - Fork 28
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
Trang & Daniela - RideShare #5
base: master
Are you sure you want to change the base?
Conversation
…ver is also a user
…new TripDispatcher
…ven_trips arrays. tests passed.
…r who hasnt driven for the longest time. tests passed.
Ride ShareWhat We're Looking For
|
def request_trip(user_id) | ||
available_drivers = @drivers.select {|driver| driver.status == :AVAILABLE and driver.id != user_id } | ||
|
||
driver = available_drivers.find {|driver| driver.driven_trips.empty?} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check your warnings. It doesn't make a huge amount of difference in THIS code, but here and on line 102, you have a "shadowed variable". driver
on the left hand side of this assignment is being covered up by |driver|
inside this find, and it creates a situation that is ambiguous to the compiler and ambiguous to a reader
start_time = Time.parse('2015-05-20T12:14:00+00:00') | ||
end_time = start_time + 25 * 60 # 25 minutes | ||
@trip_data = { | ||
data = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a compiler warning too. The way to keep the compiler from complaining is to explicitly return data
.
@@ -22,5 +26,10 @@ def inspect | |||
"ID=#{id.inspect} " + | |||
"PassengerID=#{passenger&.id.inspect}>" | |||
end | |||
|
|||
def trip_duration | |||
return @end_time == nil ? nil : duration = @end_time - @start_time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
|
||
end | ||
|
||
class Driver < User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future's reference, at least while you're still less experienced with Ruby, I'd avoid declaring 2 classes inside the same file. Especially in Ruby, this can hide problems with your code during the testing process.
def total_revenue | ||
sum = 0 | ||
|
||
@driven_trips.each do |driven_trip| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget that in Ruby you have access to methods like Sum
! I don't always think they're the best choice for every situation, but they can be an effective way to concisely communicate your thinking to readers!
OO Ride Share
Congratulations! You're submitting your assignment!
Comprehension Questions
User
andDriver