Created
October 24, 2013 23:46
-
-
Save kyletolle/7147109 to your computer and use it in GitHub Desktop.
Which method of internal processing looks or feels best? Were the internal methods used have side effects, or no?
This file contains hidden or 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
def Cherry | |
def initialize(cherry) | |
@cherry = cherry | |
end | |
def process | |
@cherry = remove_pit(@cherry) | |
@cherry = twist_stem(@cherry) | |
end | |
private | |
def remove_pit(cherry) | |
cherry.delete('pit') | |
end | |
def twist_stem(cherry) | |
cherry['stem'].twist | |
end | |
end |
This file contains hidden or 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
def Cherry | |
def initialize(cherry) | |
@cherry = cherry | |
end | |
def process | |
remove_pit | |
twist_stem | |
end | |
private | |
def remove_pit | |
@cherry.delete('pit') | |
end | |
def twist_stem | |
@cherry['stem'] = @cherry['stem'].twist | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Going with internal instance methods that have side effects.
The whole point in an instance having internal state is to be able to use it. It makes sense that internal methods are going to manipulate that state. If we're passing around methods everywhere, it might as well be a private class method, which is silly.