Class: Class
Instance Method Summary collapse
- #inspect_field_set ⇒ Object
-
#inspect_only(*methods) ⇒ Object
Override #inspect to only include the specified.
Instance Method Details
#inspect_field_set ⇒ Object
26 27 28 |
# File 'lib/iron/extensions/class.rb', line 26 def inspect_field_set @inspect_field_set || [] end |
#inspect_only(*methods) ⇒ Object
Override #inspect to only include the specified
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/iron/extensions/class.rb', line 4 def inspect_only(*methods) @inspect_field_set = methods alias_method :original_inspect, :inspect class_eval do def inspect fields = self.class.inspect_field_set vars = instance_variables field_vals = fields.collect do |field| if instance_variables.include?("@#{field}".to_sym) "@#{field}=" + instance_variable_get("@#{field}").inspect elsif respond_to?(field) ":#{field}=" + send(field).inspect end end.compact text = "#<#{self.class.name}:#{self.object_id}" text += (' ' + field_vals.list_join(', ')) if field_vals.any? text += '>' text end end end |