Skip to content

Instantly share code, notes, and snippets.

@maeharin
Last active December 10, 2015 16:18
Show Gist options
  • Save maeharin/4459714 to your computer and use it in GitHub Desktop.
Save maeharin/4459714 to your computer and use it in GitHub Desktop.
多重代入におけるto_aとto_aryの挙動の違い
# url: http://bugs.ruby-lang.org/issues/show/1393
class C
def to_a; [1,2]; end
def to_ary; [3,4]; end
end
c = C.new
# implicit(暗黙)
a, b = c
# explicit(自明)
d, e = *c
puts a, b # 3,4 on 1.8 / 3,4 on 1.9
puts d, e # 3,4 on 1.8 / 1,2 on 1.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment