Skip to content

Instantly share code, notes, and snippets.

@mistersourcerer
Created February 27, 2012 18:15
Show Gist options
  • Save mistersourcerer/1925931 to your computer and use it in GitHub Desktop.
Save mistersourcerer/1925931 to your computer and use it in GitHub Desktop.
Ruby do(repeat) until
def Repeat(&block)
_RepeatUntil = Class.new {
def repeat(&block)
block.call
@action = block
self
end
def until(&block)
until result = block.call
@action.call
end
result
end
}
_RepeatUntil.new.repeat(&block)
end
input = Repeat { print "Please, type something: " }.until {
value = gets.chomp
value.length > 0 && value
}
puts "typed: input"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment