Class: Object

Inherits:
BasicObject
Defined in:
lib/object_identifier/core_ext/object.rb

Instance Method Summary collapse

Instance Method Details

#identify(*args) ⇒ String #identify(*args, options) ⇒ String

Instance method for constructing a self-identifying string for any given object or list of objects.

Examples:

OpenStruct.new(a: 1, b: '2', c: :"3").identify(:a, :b, :c)
# => "OpenStruct[a:1, b:\"2\", c::\"3\"]"

1.identify(:to_s) # => "Integer[to_s:\"1\"]"
nil.identify      # => "[no objects]"

%w(1 2 3).identify(:to_i, :to_f)
# => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0], String[to_i:3, to_f:3.0]"

(1..10).to_a.identify(:to_f, limit: 2)
# => "Integer[to_f:1.0], Integer[to_f:2.0], ... (8 more)"

Overloads:

  • #identify(*args) ⇒ String

    Parameters:

    • args (*)

      (optional) a list of arguments to identify for this object or for each object in this collection

  • #identify(*args, options) ⇒ String

    Parameters:

    • args (*)

      (optional) (default: :id) a list of arguments to identify for this object

    • options (Hash)

      the options for building a customized self-identifier

    Options Hash (options):

    • :klass (String, nil)

      object class name override

    • :limit (Integer)

      maximum number of objects to display from a collection

Returns:

  • (String)

    a self-identifying string



39
40
41
# File 'lib/object_identifier/core_ext/object.rb', line 39

def identify(*args)
  ObjectIdentifier::Identifier.identify(self, *args)
end

#inspect_litString

Standard #inspect for any object that doesn’t override this method. This method is meant to make an object’s type inherently obvious inspected.

Returns:

  • (String)

    a String-literal representation of this object



6
7
8
# File 'lib/object_identifier/core_ext/object.rb', line 6

def inspect_lit
  inspect
end