Created
August 8, 2018 15:45
-
-
Save fwfurtado/59727e673dd9fd51edd55bbdf4939512 to your computer and use it in GitHub Desktop.
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
class Strategy: | |
registered = [] | |
def __init__(self, func): | |
self._func = func | |
Strategy.registered.append(func) | |
def __call__(self, *args, **kwargs): | |
return self._func(*args, **kwargs) |
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
from strategy import Strategy | |
@Strategy | |
def strategy_1(x, y): | |
return x + y | |
@Strategy | |
def strategy_2(x, y): | |
return x - y | |
print(Strategy.registered) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment