Module: Transproc::ProcTransformations

Extended by:
Registry
Defined in:
lib/transproc/proc.rb

Overview

Transformation functions for Procs

Examples:

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"}

Class Method Summary collapse

Methods included from Registry

[], fetch, import, store

Class Method Details

.bind(value, binding, fn) ⇒ Proc

Change the binding for the given function

Examples:

Transproc(
  :bind,
  OpenStruct.new(prefix: 'foo'),
  -> s { [prefix, s].join('_') }
)['bar']
# => "foo_bar"

Parameters:

  • (Proc)

Returns:

  • (Proc)


38
39
40
# File 'lib/transproc/proc.rb', line 38

def self.bind(value, binding, fn)
  binding.instance_exec(value, &fn)
end