Sha256: 8cf6bab407eb2fe2c2f5a2665fbac1d40c3255c44117f51a2b58e45b25ab94de

Contents?: true

Size: 835 Bytes

Versions: 5

Compression:

Stored size: 835 Bytes

Contents

module Foobara
  module Callback
    class Block
      module Concerns
        module KeywordArgumentableBlock
          def to_proc
            @to_proc ||= if has_keyword_args?
                           proc do |*args, &block|
                             original_block.call(**args.reduce(:merge), &block)
                           end
                         else
                           original_block
                         end
          end

          def validate_original_block!
            super

            if has_keyword_args? && has_positional_args?
              # TODO: raise a real error
              # :nocov:
              raise "Expect #{type} block to either take a positional arg or keyword args but not both"
              # :nocov:
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foobara-0.0.47 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.46 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.45 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.44 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.43 projects/callback/src/block/concerns/keyword_argumentable_block.rb