Created
October 21, 2013 05:00
-
-
Save aibou/7078875 to your computer and use it in GitHub Desktop.
Rubyのラムダ式まわり。func_with_blockあたりがクサい
This file contains 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
def func_without_args | |
yield if block_given? | |
end | |
def func_with_block &block | |
yield block | |
end | |
def func_with_proc p | |
p.call | |
end | |
begin | |
func_without_args -> { puts "Hello" } | |
rescue => e | |
puts e #=> wrong number of arguments (1 for 0) | |
end | |
begin | |
func_without_args &-> { puts "Hello" } #=> Hello | |
rescue => e | |
puts e | |
end | |
begin | |
func_with_block -> { puts "Hello" } | |
rescue => e | |
puts e #=> wrong number of arguments (1 for 0) | |
end | |
begin | |
func_with_block &-> { puts "Hello" } | |
rescue => e | |
puts e #=> wrong number of arguments (1 for 0) | |
end | |
begin | |
func_with_proc -> { puts "Hello" } #=> Hello | |
rescue => e | |
puts e | |
end | |
begin | |
func_with_proc &-> { puts "Hello" } | |
rescue => e | |
puts e #=> wrong number of arguments (0 for 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment