forked from jennojenno/ShoesCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.rb
More file actions
40 lines (35 loc) · 730 Bytes
/
Copy pathcalculator.rb
File metadata and controls
40 lines (35 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Shoes.app :title => "Simple Calculator", :width => 240, :height => 240 do
stack :margin => 30 do
@output = edit_line
background red
flow do
%w(1 2 3 * 4 5 6 / 7 8 9 + 0 %).each do |op|
button op do
append op
end
end
button "C" do
@output.text = 0
@input = ""
end
button "=" do
eval_expression
end
end
end
# Stick a string on the end of our input
#
def append(s)
if @input.nil?
@input = ""
end
@input += s
@output.text = @input
end
# Evaluate the input we've got so far
#
def eval_expression
@input = eval(@input).to_s
@output.text = @input
end
end