Class: PowertoolMaybeChain

Inherits:
Object
  • Object
show all
Defined in:
lib/powertool/maybe_chain.rb

Overview

A private helper for MaybeChain

Class Method Summary collapse

Class Method Details

.maybe_chain(caller, args) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/powertool/maybe_chain.rb', line 5

def self.maybe_chain(caller, args)
  args.each_with_index do |a, _i|
    return nil if caller[a].nil? || ![Hash, Array, Range].include?(caller.class)

    caller = a.instance_of?(Range) ? a.map { |i| caller[i] } : caller[a]
  end
  caller
end