Code Blocks as Commands : Command « Design Patterns « Ruby
- Ruby
- Design Patterns
- Command
Code Blocks as Commands
class Commander
attr_accessor :command
def initialize(&block)
@command = block
end
def on_button_push
@command.call if @command
end
end
new_button = Commander.new do
puts "asdf"
end
Related examples in the same category