Module: Wesabe::Util

Extended by:
Util
Included in:
BaseModel, Util
Defined in:
lib/wesabe/util.rb

Instance Method Summary collapse

Instance Method Details

#all_or_one(what) {|element| ... } ⇒ Array<Object>, Object

Yields what or, if what is an array, each element of what. It’s sort of like an argument-agnostic map.

Yield Parameters:

  • element (Object)

    If what is an Array, this is what. Otherwise it’s elements of what.

Returns:

  • (Array<Object>, Object)

    If what is an array, it acts like what.map. Otherwise yield(what).



12
13
14
15
# File 'lib/wesabe/util.rb', line 12

def all_or_one(what, &block)
  result = Array(what).each(&block)
  return what.is_a?(Array) ? result : result.first
end