Are there better ways to prevent 'yield' when no block is passed in?

前端 未结 1 1285
天涯浪人
天涯浪人 2020-12-29 03:14

I have a method that yields, which looks like:

def a_method(*params)
  # do something
  yield
  # do something else
end

I want this method

相关标签:
1条回答
  • 2020-12-29 03:45

    Yes! :)

    def a_method(*params)
      # ...
      yield if block_given?
      # ...
    end
    
    0 讨论(0)
提交回复
热议问题