Skip to content

Commit

Permalink
Merge pull request #404 from asaffifee/patch-1
Browse files Browse the repository at this point in the history
Pass the `move` object to the `do_action()` method
  • Loading branch information
faif authored Jan 27, 2023
2 parents 93bfb7f + 4e62fd0 commit d4b7f97
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions patterns/behavioral/chaining_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@


class Person:
def __init__(self, name: str, action: Action) -> None:
def __init__(self, name: str) -> None:
self.name = name
self.action = action

def do_action(self) -> Action:
print(self.name, self.action.name, end=" ")
return self.action
def do_action(self, action: Action) -> Action:
print(self.name, action.name, end=" ")
return action


class Action:
Expand All @@ -26,8 +25,8 @@ def stop(self) -> None:
def main():
"""
>>> move = Action('move')
>>> person = Person('Jack', move)
>>> person.do_action().amount('5m').stop()
>>> person = Person('Jack')
>>> person.do_action(move).amount('5m').stop()
Jack move 5m then stop
"""

Expand Down

0 comments on commit d4b7f97

Please sign in to comment.