-
-
Save tkadauke/254898 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def index_of(&block) | |
each_with_index do |item, index| | |
return index if yield(item) | |
end | |
end | |
end | |
def print_these_strings(&block) | |
block.inspect =~ /#<Proc:.*?@(.*?):(.*?)>/ | |
file, line = $1, $2.to_i | |
contents = File.read(file).split("\n") | |
line.times { contents.shift } | |
last_line = contents.index_of { |line| line =~ /^\s*end\s*$/ } | |
contents = contents[0..(last_line - 1)] | |
array = [] | |
contents.each do |content| | |
array << eval(content) | |
end | |
puts array.join(" and ") | |
end | |
print_these_strings do | |
"hello" | |
"goodbye" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment