Block: just a piece of code, equivalent to an anonymous function; Closure (Closures): a code, can be passed to other methods as parameters. Let's go back and look at the automatic card player. At some point, we need to deal with the interlocking machine and user interface: Many buttons for users to choose songs and control playback, we need to specify the corresponding time handled code, and Ruby Block is very suitable for doing this. Assume that the designer of the singer has provided us with a basic button class through the Ruby extension.
Bstart = button.new ("start")
BPAUSE = Button.New ("pause")
# ...
How to deal with the user after pressing the button? The Button class provides a ButtonPressed method that can be called when the button is pressed. So the easiest way to create the subscar class of Button and then implement the ButtonPressed method in each subclass.