Sha256: 8164f5e966e084ff131f11fb7c65ff13ea3d1fd4a4efa512ebd302472cc67076

Contents?: true

Size: 848 Bytes

Versions: 4

Compression:

Stored size: 848 Bytes

Contents

module Transproc
  # Transformation functions for Procs
  #
  # @example
  #   require 'ostruct'
  #   require 'transproc/proc'
  #
  #   include Transproc::Helper
  #
  #   fn = t(
  #     :map_value,
  #     'foo_bar',
  #     t(:bind, OpenStruct.new(prefix: 'foo'), -> s { [prefix, s].join('_') })
  #   )
  #
  #   fn["foo_bar" => "bar"]
  #   # => {"foo_bar" => "foo_bar"}
  #
  # @api public
  module ProcTransformations
    extend Registry

    # Change the binding for the given function
    #
    # @example
    #   Transproc(
    #     :bind,
    #     OpenStruct.new(prefix: 'foo'),
    #     -> s { [prefix, s].join('_') }
    #   )['bar']
    #   # => "foo_bar"
    #
    # @param [Proc]
    #
    # @return [Proc]
    #
    # @api public
    def self.bind(value, binding, fn)
      binding.instance_exec(value, &fn)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
transproc-1.0.3 lib/transproc/proc.rb
transproc-1.0.2 lib/transproc/proc.rb
transproc-1.0.1 lib/transproc/proc.rb
transproc-1.0.0 lib/transproc/proc.rb