Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Jun 7, 2019

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

@igbanam

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.