Sha256: ef035ee220415272625abec8baf40ce8ef46949cd67f7011bc78fef650c549e5

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Finix
  module Utils
    def eval_class(slf, name)
      mod = slf.class.name.split("::").first unless slf.kind_of? Class or slf.kind_of? Module
      mod = slf.name.split("::").first if mod.nil?
      self.instance_eval "#{mod}::#{name}"
    end

    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.15 lib/finix/utils.rb
finix-0.14 lib/finix/utils.rb
finix-0.13 lib/finix/utils.rb
finix-0.12 lib/finix/utils.rb