Skip to content

Instantly share code, notes, and snippets.

@laser
Last active January 3, 2016 15:29
Show Gist options
  • Save laser/8483003 to your computer and use it in GitHub Desktop.
Save laser/8483003 to your computer and use it in GitHub Desktop.
Pure functions in Ruby
class StatefulCalculator
def initialize
@total = 0
end
def add(x)
@total += x
self
end
def result
@total
end
end
class StatelessCalculator
def self.add(x, y)
x + y
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment