Skip to content

Conversation

@mlustig-cmm
Copy link

gem_city.rb Outdated
def initialize
@people = {
thieves: 5,
officers: 1 }
Copy link
Member

Choose a reason for hiding this comment

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

It would be simpler if these weren't stuck together in @people. Try defining them as @thieves and @officers.

@mlustig-cmm
Copy link
Author

Good point.

gem_city.rb Outdated
end

def successful_crime_rate
if @thieves <= 0 || @officers > thieves
Copy link
Member

Choose a reason for hiding this comment

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

Whenever these if conditions get even a little complicated, I think they should be extracted to a private method. What do you think a good name for this condition might be? no_crime_can_occur?, plenty_of_cops?, something like that.

Copy link
Author

Choose a reason for hiding this comment

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

I prefer no_crime_can_occur? because it captures the meaning of the method without exposing how the method makes that decision.

gem_city.rb Outdated
end

def no_crimes_can_occur?
@thieves <= 0 || @officers > @thieves
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 it is a little better to use the reader methods for instance variables even inside the class. In the off chance they get refactored into real methods someday, this line shouldn't need to change.

Copy link
Author

Choose a reason for hiding this comment

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

Is there a way to do that without angering rubocop?

Copy link
Member

Choose a reason for hiding this comment

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

What's it complaining about?

Copy link
Author

Choose a reason for hiding this comment

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

It was complaining about me not understanding the intent until just now. I think that I have it now.

@mikegee
Copy link
Member

mikegee commented Mar 11, 2016

This is looking real nice. 👍

@mlustig-cmm
Copy link
Author

Thank you.

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