Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active March 31, 2017 14:51
Show Gist options
  • Save yancya/3b5b27690429467bde47322c3b0d0e27 to your computer and use it in GitHub Desktop.
Save yancya/3b5b27690429467bde47322c3b0d0e27 to your computer and use it in GitHub Desktop.
2.4.1 からエラー出るようになったやつ
proc = -> (_, o) { p o }
[1,2].tap { |_, o| p o } #=> 2
[1,2].tap(&proc) #=> wrong number of arguments (given 1, expected 2) (ArgumentError)
@hanachin
Copy link

2.1まではエラーだったのが2.2からエラー出ないようになってたと思います。
https://bugs.ruby-lang.org/issues/9605#note-12

% ruby -ve 'plus = ->(x,y) {next x+y}; [1,2].tap(&plus)'
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin16.0]
-e:1:in `block in <main>': wrong number of arguments (1 for 2) (ArgumentError)
        from -e:1:in `tap'
        from -e:1:in `<main>'
% ruby -ve 'plus = ->(x,y) {next x+y}; [1,2].tap(&plus)'
ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-darwin16]
% ruby -ve 'plus = ->(x,y) {next x+y}; [1,2].tap(&plus)'
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]

@yancya
Copy link
Author

yancya commented Mar 31, 2017

なるほどー

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment