Created
March 30, 2017 06:49
-
-
Save bparanj/6458917961a11c376048e7ae9baf669d to your computer and use it in GitHub Desktop.
Ruby Object Model Exercise #2
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
sum = 0 | |
i = 1 | |
while i < 5 | |
sum += i | |
i += 1 | |
end | |
p sum |
sum = 0
i = 1
# Some code here
# The condition variable is a Proc object.
condition.while_true do
sum += i
i += 1
end
p sum
sum = 0
i = 1
class Proc
def while_true
yield while self.call
end
end
condition = Proc.new{ i < 5 }
condition.while_true do
sum += i
i += 1
end
puts sum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implement message centric Ruby equivalent.