#1:
Define a class Calc. This class has the following 18 methods.
- initialize
- to_s
- press_0, press_1, ….. , press_9
- press_clear
- press_add, press_sub, press_times, press_div
- press_equal
#2:
Define a method initialize. This method is used once in the above code to create just one object at #9.
#3:
Define a method to_s. In Shoes, para uses to_s implicitly at #10. If you comment out to_s definition lines, you will see the following output.
simple-calc-1.png
#4:
Define methods press_0, press_1, ….. , press_9 with the method define_method. See ri Module#define_method. They are the same as the following.
#6:
Execute the previous calculation (one of +, -, *, /).
#7:
To clear the number_field at #13 (to show nothing), assign nil to @number instead of 0.
#8:
Define a method press_equals. See the following small IRB snippet.
irb_session
123
C:\>irb--simple-prompt>>23.send'+',5=>28
#12:
Send the value (character string) that was assigned to the local variable method to the object number that was created at #9. See the following small IRB snippet.