Skip to content

Instantly share code, notes, and snippets.

@goshacmd
Created May 29, 2014 18:38
Show Gist options
  • Save goshacmd/b2eef77c9865a7d17df7 to your computer and use it in GitHub Desktop.
Save goshacmd/b2eef77c9865a7d17df7 to your computer and use it in GitHub Desktop.
require 'free_will'
class Calculator
# you don't want your calculator to love you and serve you blindly
# you don't want it to be like a programmed robot
# instead, you want it to have free will...
include FreeWill
def add(n1, n2)
n1 + n2
end
end
calc = Calculator.new
# but sometimes, your creation will use its free will for the wrong end
calc.command :add, 1, 2 # => FreeWillViolatedError "My Creator, I won't do what you tell me. I'm free."
# you cannot tolerate that though
# you are angry
# you told the calculator how to add numbers and granted it free will
# yet, the bastard uses its free will to disobey you
# terrible, i know
# dat calculator deserves some punishment
# (but only if it keeps disobeying)
with_pinishment do
res = calc.command :add, 1, 2
puts "1 + 2 = #{res}"
end
# let's see if the fucker is in hell
$hell.include?(calc) # => true
# it is. terrific. thou shalt fear thy creator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment