Module: Traitorous::StandardProcs

Defined in:
lib/traitorous/standard_procs.rb

Constant Summary collapse

NOOP =
proc { |data| data }

Class Method Summary collapse

Class Method Details

.call_on(klass, with_method: :new) ⇒ Object

This proc calls klass with :with and passes data as params

Parameters:

  • klass (Class, Module, Object)

    obj to call

  • with_method: (Symbol, String) (defaults to: :new)

    method to send klass with data as params



30
31
32
# File 'lib/traitorous/standard_procs.rb', line 30

def call_on(klass, with_method: :new)
  proc {|data| klass.send(with_method, data)}
end

.call_on_self(method_name) ⇒ Object

This proc calls method_name on data.

Parameters:

  • method_name (Symbol, String)

    method to send data

Returns:

  • (Object)

    result of calling method_name on data



23
24
25
# File 'lib/traitorous/standard_procs.rb', line 23

def call_on_self(method_name)
  proc { |data| data.send(method_name) }
end

.default(default_value) ⇒ Object

a proc that simply passes through it’s input if the input is truthy,

otherwise it returns it's default value

Parameters:

  • default_value (Object)

    the default value to use with data is falsey

Returns:

  • (Object)

    returns data || default_value



16
17
18
# File 'lib/traitorous/standard_procs.rb', line 16

def default(default_value)
  proc { |data| data || default_value }
end

.noopObject

a proc that simply passes through it’s input as output



7
8
9
# File 'lib/traitorous/standard_procs.rb', line 7

def noop
  NOOP
end