Module: VmShepherd::BackportRefinements

Defined in:
lib/vm_shepherd/backport_refinements.rb

Class Method Summary collapse

Class Method Details

.ported_dig(obj, indices) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vm_shepherd/backport_refinements.rb', line 9

def self.ported_dig(obj, indices)
  head = indices.first
  new_obj = obj[head]
  if indices.count == 1
    new_obj
  elsif new_obj == nil
    return nil
  else
    tail = indices[1..-1]
    ported_dig(new_obj, tail)
  end
end

.ported_dig_for_recursive_open_struct(obj, indices) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vm_shepherd/backport_refinements.rb', line 22

def self.ported_dig_for_recursive_open_struct(obj, indices)
  head = indices.first

  if head.is_a?(Integer)
    new_obj = obj[head]
  elsif
    new_obj = obj[head] || obj[head.to_sym]
  end

  if indices.count == 1
    new_obj
  elsif new_obj == nil
    return nil
  else
    tail = indices[1..-1]
    ported_dig(new_obj, tail)
  end
end

.should_refine?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/vm_shepherd/backport_refinements.rb', line 5

def self.should_refine?
  Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
end