Class: RuGUI::BaseObject

Inherits:
Object show all
Includes:
FrameworkAdapters::FrameworkAdapterSupport
Defined in:
lib/rugui/base_object.rb

Overview

A base object for all RuGUI classes.

It mainly defines customized inspect which will display only some of the instance variables, avoiding excessive overhead when generating tracebacks.

Instance Method Summary collapse

Methods included from FrameworkAdapters::FrameworkAdapterSupport

#framework_adapter_for, included, #load_framework_adapter

Instance Method Details

#inspectObject

Returns a string containing a human-readable representation of obj.

It will display each instance variable value unless it is also a RuGUI::BaseObject.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rugui/base_object.rb', line 14

def inspect
  instance_variables_values = instance_variables.collect do |instance_variable_name|
    instance_variable_value = instance_variable_get(instance_variable_name)
    inspected_instance_variable_value = nil
    if instance_variable_value.is_a?(RuGUI::BaseObject)
      inspected_instance_variable_value = inspect_base_object(instance_variable_value)
    elsif instance_variable_value.is_a?(Array)
      inspected_instance_variable_value = inspect_array(instance_variable_value)
    elsif instance_variable_value.is_a?(Hash)
      inspected_instance_variable_value = inspect_hash(instance_variable_value)
    else
      inspected_instance_variable_value = instance_variable_value.inspect
    end

    "#{instance_variable_name}=#{inspected_instance_variable_value}"
  end

  "#<#{self.class.name} #{instance_variables_values.join(" ")}>"
end