Module: MiniObject::RemarkableInspect::ClassMethods

Defined in:
lib/mini_object/remarkable_inspect.rb

Instance Method Summary collapse

Instance Method Details

#formatted_nameObject



41
42
43
44
# File 'lib/mini_object/remarkable_inspect.rb', line 41

def formatted_name
  first_ancestor_name = ancestors.map(&:name).compact.first
  name || "#{first_ancestor_name}:0x#{'%x' % (object_id << 1)}"
end

#inspectObject



24
25
26
# File 'lib/mini_object/remarkable_inspect.rb', line 24

def inspect
  "#{formatted_name}( #{remarkable_methods.join(", ")} )"
end

#remarkable_methodsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mini_object/remarkable_inspect.rb', line 28

def remarkable_methods
  (self.instance_methods - Box.instance_methods).sort.map(&:to_s).tap do |mm|
    # Substittues [my_method, my_method=] by [my_method/=]
    mm.grep(/\=$/).each do |setter|
      getter = setter.gsub /\=$/, ''
      if mm.include? getter
        mm.delete setter
        mm[mm.find_index(getter)] = setter.gsub /\=$/, '/='
      end
    end
  end
end