-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
33 lines (30 loc) · 779 Bytes
/
test.rb
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
def do_until_false first_input, some_proc
input = first_input
output = first_input
while output
input = output
output = some_proc.call input
end
input
end
build_array_of_squares = Proc.new do |array|
last_number = array.last
if last_number <= 0
false
else
# Take off the last number...
array.pop
# ...and replace it with its square...
array.push last_number*last_number
# ...followed by the next smaller number.
array.push last_number-1
end
end
always_false = Proc.new do |just_ignore_me|
false
end
puts do_until_false([5], build_array_of_squares).inspect
yum = 'lemonade with a hint of orange blossom water'
puts do_until_false(yum, always_false)
[25, 16, 9, 4, 1, 0]
lemonade with a hint of orange blossom water