Is it possible to declare a method with block as default value?
问题 I want to write a method which takes a block and if no block given it should use a default block. So I want to have something like this: def say_hello(name, &block = ->(name) { puts "Hi, #{name}" }) # do something end But when I'm trying to do so I'm getting the syntax error. I know I can deal with my problem using block_given?. But I am interested in first approach. Am I missing something or this is just not possible? 回答1: Some answers suggest using block_given? , but since there is no