Last active
June 11, 2019 14:26
-
-
Save igbanam/dd3346c583e0e0bfad25e02c8dbc6dee to your computer and use it in GitHub Desktop.
Methods are better without assignments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
This actually makes a lot of sense, to be honest. Might result in a pretty bloated class, but...it makes sense.