Skip to content

Instantly share code, notes, and snippets.

@banyan
Created December 24, 2009 15:54
Show Gist options
  • Select an option

  • Save banyan/263240 to your computer and use it in GitHub Desktop.

Select an option

Save banyan/263240 to your computer and use it in GitHub Desktop.
[1, 2, 3, 4, 5].each do |i|
p i * 2
end
#2
#4
#6
#8
#10
# 同じことを再帰を使って表現する
def rec(ary)
return if ary.empty?
p ary[0] * 2
rec(ary.slice(1..-1))
end
rec([1,2,3,4,5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment