Module: Hashie::Utils
- Defined in:
- lib/hashie/utils.rb
Overview
A collection of helper methods that can be used throughout the gem.
Class Method Summary collapse
-
.integer_classes ⇒ Array<Class>
private
Lists the classes Ruby uses for integers.
-
.method_information(bound_method) ⇒ String
Describes a method by where it was defined.
-
.safe_dup(value) ⇒ Object
Duplicates a value or returns the value when it is not duplicable.
Class Method Details
.integer_classes ⇒ Array<Class>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lists the classes Ruby uses for integers
35 36 37 38 39 40 41 42 |
# 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) ⇒ String
Describes a method by where it was defined.
8 9 10 11 12 13 14 |
# 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) ⇒ Object
Duplicates a value or returns the value when it is not duplicable
22 23 24 25 26 27 28 29 |
# 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 |