Skip to content

Instantly share code, notes, and snippets.

@kyletolle
Created October 24, 2013 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyletolle/7147109 to your computer and use it in GitHub Desktop.
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?
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
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
@kyletolle
Copy link
Author

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.

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