class Object
Public Instance Methods
what_the() { |"Found me!..\nYou can move on\n".yellow| ... }
click to toggle source
# 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