Module: Mixins::Inspection
- Defined in:
- lib/mixins/inspection.rb
Overview
An extensible #inspect.
This adds an overloaded #inspect method to including classes that provides a way to easily extend the default #inspect output. To add your own output to the body of the inspected object, implement the #inspect_details method and return your desired output from it. By default it returns the empty string, which will cause #inspect to use the default output.
Instance Method Summary collapse
-
#inspect ⇒ Object
Return a human-readable representation of the object suitable for debugging.
-
#inspect_details ⇒ Object
Return the detail portion of the inspect output for this object.
Instance Method Details
#inspect ⇒ Object
Return a human-readable representation of the object suitable for debugging.
16 17 18 19 20 21 22 23 |
# File 'lib/mixins/inspection.rb', line 16 def inspect details = self.inspect_details details = ' ' + details unless details.empty? || details.start_with?( ' ' ) default = super return default.sub( /\s.*\z/, details << '>' ) end |
#inspect_details ⇒ Object
Return the detail portion of the inspect output for this object.
27 28 29 |
# File 'lib/mixins/inspection.rb', line 27 def inspect_details return '' end |