Sha256: 901ec256fe91b8bc89f0abce03b77979781feee80a8041af352bf98c6b4df0dc

Contents?: true

Size: 940 Bytes

Versions: 4

Compression:

Stored size: 940 Bytes

Contents

module Finix
  module Utils

    def callable(callable_or_not)
      callable_or_not.respond_to?(:call) ? callable_or_not : lambda { callable_or_not }
    end

    def indifferent_read_access(base = {})
      indifferent = Hash.new do |hash, key|
        hash[key.to_s] if key.is_a? Symbol
      end
      base.each_pair do |key, value|
        if value.is_a? Hash
          value = indifferent_read_access value
        elsif value.respond_to? :each
          if value.respond_to? :map!
            value.map! do |v|
              if v.is_a? Hash
                v = indifferent_read_access v
              end
              v
            end
          else
            value.map do |v|
              if v.is_a? Hash
                v = indifferent_read_access v
              end
              v
            end
          end
        end
        indifferent[key.to_s] = value
      end
      indifferent
    end

    extend self
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
finix-0.11 lib/finix/utils.rb
finix-0.10 lib/finix/utils.rb
finix-0.9 lib/finix/utils.rb
finix-0.8 lib/finix/utils.rb