Created
January 18, 2013 11:43
-
-
Save NigelThorne/4564112 to your computer and use it in GitHub Desktop.
Functional While look in ruby
This file contains hidden or 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 While | |
def initialize(&src_fn) | |
@src_fn = src_fn | |
end | |
def do | |
x = @src_fn.call | |
while(x) | |
yield(x) | |
x = @src_fn.call | |
end | |
end | |
end | |
# While.new{@a = 1 + (@a || 0); @a <= 100 ? @a : nil}.do{|x| puts x} | |
# counts up to 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment