Module: Arx::Inspector
Overview
Restricts inspect
to dump a whitelist of methods on an object. It will always provide ‘object_id` at a minimum.
Class Method Summary collapse
-
.included(source) ⇒ Object
Defines helper
inspector_fields
instance variable & method, andinspector
instance method on the target object. -
.inspected ⇒ Object
Returns the
inspected
instance variable, or sets it if undefined.
Instance Method Summary collapse
-
#inspect ⇒ Object
Overwrites the object’s own inspect method.
Class Method Details
.included(source) ⇒ Object
Defines helper inspector_fields
instance variable & method, and inspector
instance method on the target object.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/arx/inspector.rb', line 30 def included(source) inspected << source source.class_eval do def self.inspector(*fields) @inspector_fields = *fields end def self.inspector_fields @inspector_fields ||= [] end end end |
.inspected ⇒ Object
Returns the inspected
instance variable, or sets it if undefined.
23 24 25 |
# File 'lib/arx/inspector.rb', line 23 def inspected @inspected ||= [] end |
Instance Method Details
#inspect ⇒ Object
Overwrites the object’s own inspect method.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/arx/inspector.rb', line 10 def inspect pairs = {} self.class.inspector_fields.each do |field| pairs[field] = self.send(field).inspect rescue end "#<#{self.class.name}:#{self.object_id} #{pairs.map {|k,v| "#{k}=#{v}"}.join(", ")}>" end |