Last active
December 11, 2015 19:08
-
-
Save tigawa/4645952 to your computer and use it in GitHub Desktop.
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
animals = %w( ant bee cat dog elk ) #配列を作成 | |
animals.each{|animal| puts animal } | |
#3回繰り返す。 | |
3.times { print "ホー!" } #~> ホー!ホー!ホー! | |
#&接頭演算子 | |
def wrap &b | |
print "さんたのことば:" | |
3.times(&b) | |
print "\n" | |
end | |
wrap {print "ホー!" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment