Module: ChainOptions::Util

Defined in:
lib/chain_options/util.rb

Defined Under Namespace

Classes: ContextBoundDelegate

Class Method Summary collapse

Class Method Details

.blank?(obj) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/chain_options/util.rb', line 5

def self.blank?(obj)
  (obj.is_a?(Enumerable) && obj.empty?) || obj.nil? || obj == ""
end

.instance_eval_or_call(object, &block) ⇒ Object

Evaluate the given proc in the context of the given object if the block’s arity is non-positive, or by passing the given object as an argument if it is negative.

Parameters

object<Object>

Object to pass to the proc



24
25
26
27
28
29
30
# File 'lib/chain_options/util.rb', line 24

def self.instance_eval_or_call(object, &block)
  if block.arity.positive?
    block.call(object)
  else
    ContextBoundDelegate.instance_eval_with_context(object, &block)
  end
end

.slice(hash, keys) ⇒ Object



9
10
11
12
13
# File 'lib/chain_options/util.rb', line 9

def self.slice(hash, keys)
  keys.each_with_object({}) do |key, h|
    h[key] = hash[key] if hash[key]
  end
end