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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/yield_source.rb', line 5
def what_the()
system 'clear'
if !File.file?("./zmem.txt")
if !block_given?
puts
puts("Come on! Give me a block!".yellow)
print("(Remember what you do with a ".blue)
print(".each ".red)
puts("loop..)".blue)
puts
File.open("./zmem.txt", 'w') { |file| file.write("mem=1") }
else
puts("\nHow did this work?!".red)
puts("Where is this coming from?\n".light_blue)
yield("Found me!..\nYou can move on\n".yellow)
end
else
if !block_given?
content = File.read("./zmem.txt")
content_arr = content.split('=')
times = content_arr[1]
if times == "1"
puts
puts("Really?! Still no block?! If you get it wrong again, I'll give you a hint..".yellow)
puts
File.open("./zmem.txt", 'w') { |file| file.write("mem=2") }
elsif times == "2"
puts
puts("Hmm, ok then.".light_blue)
puts("This is a method that takes a block.".yellow)
print("Blocks start with a ".light_blue)
print("do".red)
print(", and close with an ".light_blue)
print("end".red)
puts(".".light_blue)
puts
File.open("./zmem.txt", 'w') { |file| file.write("mem=3") }
elsif times == "3"
puts("\nAlso, blocks sometimes take a block argument, which will help you out during this challenge.\n".yellow)
File.open("./zmem.txt", 'w') { |file| file.write("mem=4") }
else
puts
puts("If you are still getting this wrong, you need to slack someone!".red)
puts
end
else
puts("\nHow did this work?!".red)
puts("Where is this coming from?\n".light_blue)
yield("Found me!..\nYou can move on!\n".yellow)
end
end
end
|