Using 'return' in a Ruby block

后端 未结 7 820
太阳男子
太阳男子 2020-11-28 03:54

I\'m trying to use Ruby 1.9.1 for an embedded scripting language, so that \"end-user\" code gets written in a Ruby block. One issue with this is that I\'d like the users to

7条回答
  •  無奈伤痛
    2020-11-28 04:31

    You are looking it from the wrong point of view. This is an issue of thing, not the lambda.

    def thing(*args, &block)
      block.call.tap do |value|
        puts "value=#{value}"
      end
    end
    
    thing {
      6 * 7
    }
    

提交回复
热议问题