Is it possible to declare a method with block as default value?
block, lambda, ruby
Solution
Some answers suggest using `block_given?`, but since there is no possibility that a block would be `nil` or `false` when it is given, you can simply use `||=`.
def say_hello(name, &block)
block ||= ->(name){puts "Hi, #{name}"}
# do something
end
Problem
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?