Skip to content

Instantly share code, notes, and snippets.

@dstarh
Last active August 29, 2015 14:14
Show Gist options
  • Save dstarh/2da1a324dad8149ab201 to your computer and use it in GitHub Desktop.
Save dstarh/2da1a324dad8149ab201 to your computer and use it in GitHub Desktop.
def while_with_index(proc, &block)
index = 0
loop do
break unless proc.call
yield index
index += 1
end
end
a = "woot"
while_with_index(Proc.new {a != "foobar" }) do |index|
puts "index = #{index}"
a = "foobar" if index == 10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment