Skip to content

Instantly share code, notes, and snippets.

@nafidurmus
Last active August 2, 2019 11:13
Show Gist options
  • Save nafidurmus/c0027d8d8e61346fcb6ad4261743b57f to your computer and use it in GitHub Desktop.
Save nafidurmus/c0027d8d8e61346fcb6ad4261743b57f to your computer and use it in GitHub Desktop.
class UIButton
attr_reader :command
def initialize(command)
@command = command
end
def press_button
@command.execute
end
end
class AddItemToCartCommand
attr_reader :item, :cart
def initialize(item, cart)
@item = item
@cart = cart
end
def execute
@cart.add_item(@item)
end
def unexecute
@cart.remove_item(@item)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment