module Hashie::Utils

A collection of helper methods that can be used throughout the gem.

Public Class Methods

integer_classes() click to toggle source

Lists the classes Ruby uses for integers

@api private @return [Array<Class>]

# File lib/hashie/utils.rb, line 35
def self.integer_classes
  @integer_classes ||=
    if 0.class == Integer
      [Integer]
    else
      [Fixnum, Bignum] # rubocop:disable Lint/UnifiedInteger
    end
end
method_information(bound_method) click to toggle source

Describes a method by where it was defined.

@param bound_method [Method] The method to describe. @return [String]

# File lib/hashie/utils.rb, line 8
def self.method_information(bound_method)
  if bound_method.source_location
    "defined at #{bound_method.source_location.join(':')}"
  else
    "defined in #{bound_method.owner}"
  end
end
safe_dup(value) click to toggle source

Duplicates a value or returns the value when it is not duplicable

@api public

@param value [Object] the value to safely duplicate @return [Object] the duplicated value

# File lib/hashie/utils.rb, line 22
def self.safe_dup(value)
  case value
  when Complex, FalseClass, NilClass, Rational, Method, Symbol, TrueClass, *integer_classes
    value
  else
    value.dup
  end
end