Last active
December 10, 2015 16:18
-
-
Save maeharin/4459714 to your computer and use it in GitHub Desktop.
多重代入におけるto_aとto_aryの挙動の違い
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
# 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