Sha256: 1779182fa983f63139b3b85b94143ce689d0f8087bf2013c90feb8d05eb7d2fe

Contents?: true

Size: 898 Bytes

Versions: 26

Compression:

Stored size: 898 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|
                             keyword_args = args.reduce(:merge) || {}
                             original_block.call(**keyword_args, &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

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.25 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.24 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.23 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.22 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.21 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.20 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.19 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.18 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.17 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.16 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.15 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.14 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.13 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.12 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.11 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.10 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.9 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.8 projects/callback/src/block/concerns/keyword_argumentable_block.rb
foobara-0.0.7 projects/callback/src/block/concerns/keyword_argumentable_block.rb