Module: ChainOptions::Util
- Defined in:
- lib/chain_options/util.rb
Defined Under Namespace
Classes: ContextBoundDelegate
Class Method Summary collapse
- .blank?(obj) ⇒ Boolean
-
.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.
- .slice(hash, keys) ⇒ Object
Class Method Details
.blank?(obj) ⇒ Boolean
6 7 8 |
# File 'lib/chain_options/util.rb', line 6 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
25 26 27 28 29 30 31 |
# File 'lib/chain_options/util.rb', line 25 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
10 11 12 13 14 |
# File 'lib/chain_options/util.rb', line 10 def self.slice(hash, keys) keys.each_with_object({}) do |key, h| h[key] = hash[key] if hash[key] end end |