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

Initial cut #15

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

Conversation

mlustig-cmm
Copy link

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.

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.

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