Last active
August 29, 2015 14:05
-
-
Save memetor/f9b69a3ffbe8968f8ee6 to your computer and use it in GitHub Desktop.
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
# cf. http://www.slideshare.net/esehara/for-38276816 | |
# 1 | |
i = 1 | |
while i <= 10 do | |
puts i | |
i += 1 | |
end | |
# 2 | |
(1..10).each(&method(:puts)) | |
# 3 | |
def r(n = 1) | |
puts n | |
r(n + 1) unless n == 10 | |
end | |
r | |
# 4 | |
class Fixnum | |
def r | |
puts self | |
(self + 1).r unless self == 10 | |
end | |
end | |
1.r | |
# 5 | |
puts 1 | |
puts 2 | |
puts 3 | |
puts 4 | |
puts 5 | |
puts 6 | |
puts 7 | |
puts 8 | |
puts 9 | |
puts 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment