Sha256: b9014e20b0a3a40abfa148285e3a1857b74eee30f18974f14b0521a9cab09fe3

Contents?: true

Size: 700 Bytes

Versions: 3

Compression:

Stored size: 700 Bytes

Contents

module Mirrors
  # A mirror class. It is the most generic mirror and should be able
  # to reflect on any object you can get at in a given system.
  class ObjectMirror < Mirror
    # @return [FieldMirror] the instance variables of the object
    def variables
      field_mirrors(@subject.instance_variables)
    end

    # @return [ClassMirror] the a class mirror on the runtime class object
    def target_class
      Mirrors.reflect(@subject.class)
    end

    private

    def field_mirrors(list, subject = @subject)
      list.map { |name| field_mirror(subject, name) }
    end

    def field_mirror(subject, name)
      Mirrors.reflect(FieldMirror::Field.new(subject, name))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mirrors-0.0.3 lib/mirrors/object_mirror.rb
mirrors-0.0.2 lib/mirrors/object_mirror.rb
mirrors-0.0.1 lib/mirrors/object_mirror.rb