Created
June 9, 2011 19:16
-
-
Save mazur/1017481 to your computer and use it in GitHub Desktop.
This file contains 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
interface IOperator do | |
def run(x:int, y:int) | |
returns int | |
end | |
end | |
class Add | |
implements IOperator | |
def run(x:int, y:int) | |
returns int | |
x + y | |
end | |
end | |
class Sub | |
implements IOperator | |
def run(x:int, y:int) | |
returns int | |
x - y | |
end | |
end | |
class Operators | |
def add | |
Add.new | |
end | |
def sub | |
Sub.new | |
end | |
end | |
def calculate(op:IOperator) | |
op.run(4, 20) | |
end | |
ops = Operators.new | |
puts calculate ops.add | |
puts calculate ops.sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment