Module: RSMP::Inspect
- Included in:
- Archive, ComponentBase, Distributor, Message, Node, Proxy, Receiver
- Defined in:
- lib/rsmp/helpers/inspect.rb
Overview
Custom inspect, to reduce noise
Instance variables of classes starting with Async or RSMP are shown with only their class name and object id, which reduces output, especially for deep object structures. Additionally, a list of variables to shown in short format can be passed.
The short form is generated by using to_s() insted of inspect()
Array#to_s and Hash#to_s usually show items, but here we show just number of items, when the short form is requested.
Instance Method Summary collapse
-
#inspect ⇒ Object
override this if you want additional variable to be shown in the short format, or ottherwise change the inspect format.
- #inspector(*short_items) ⇒ Object
Instance Method Details
#inspect ⇒ Object
override this if you want additional variable to be shown in the short format, or ottherwise change the inspect format
37 38 39 |
# File 'lib/rsmp/helpers/inspect.rb', line 37 def inspect "#<#{self.class.name}:#{object_id}, #{inspector}>" end |
#inspector(*short_items) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rsmp/helpers/inspect.rb', line 14 def inspector(*short_items) instance_variables.map do |var_name| var = instance_variable_get(var_name) class_name = var.class.name short = short_items.include?(var_name) || class_name.start_with?('Async') || class_name.start_with?('RSMP') if short if var.is_a?(Array) || var.is_a?(Hash) "#{var_name}: #<#{class_name}:#{class_name.object_id}, #{var.size} items>" else "#{var_name}: #{var}" end else "#{var_name}: #{var.inspect}" end end.join(', ') end |