Skip to content

Instantly share code, notes, and snippets.

@tigawa
Last active December 11, 2015 19:08
Show Gist options
  • Save tigawa/4645952 to your computer and use it in GitHub Desktop.
Save tigawa/4645952 to your computer and use it in GitHub Desktop.
ruby イテレータ 接頭演算子
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