Skip to content

Instantly share code, notes, and snippets.

@tkadauke
Forked from addywaddy/gist:222349
Created December 12, 2009 14:15
Show Gist options
  • Save tkadauke/254898 to your computer and use it in GitHub Desktop.
Save tkadauke/254898 to your computer and use it in GitHub Desktop.
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