Skip to content

Instantly share code, notes, and snippets.

@igbanam
Last active June 11, 2019 14:26
Show Gist options
  • Save igbanam/dd3346c583e0e0bfad25e02c8dbc6dee to your computer and use it in GitHub Desktop.
Save igbanam/dd3346c583e0e0bfad25e02c8dbc6dee to your computer and use it in GitHub Desktop.
Methods are better without assignments
class SomethingWithAssignments
def nice
first_thing = @modifier * 2
another_thing = some_method.to_i
three_divides = @modifier % 3 == 0 ? true : false
if three_divides
return first_thing + another_thing
else
return another_thing
end
end
end
class SomethingWithoutAssignments
def nice
return first_thing + another_thing if three_divides?
another_thing
end
protected
def first_thing
@modifier * 2
end
def another_thing
some_method.to_i
end
def three_divides?
@modifier % 3 == 0
end
end
@madeofhuman
Copy link

This actually makes a lot of sense, to be honest. Might result in a pretty bloated class, but...it makes sense.

@igbanam
Copy link
Author

igbanam commented Jun 11, 2019

Yeah, @madeofhuman. I see how classes can easily blow up. Once we see classes are getting longer than necessary, then we can take similar functions into a module, or create another class for different concepts which show themselves, and so on.

This is the beginning of the refactor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment