Module: Celerity::ShortInspect

Included in:
Container
Defined in:
lib/celerity/short_inspect.rb

Instance Method Summary collapse

Instance Method Details

#short_inspect(opts) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/celerity/short_inspect.rb', line 4

def short_inspect(opts)
  if excluded_ivars = opts[:exclude]
    if is_ruby19
      excluded_ivars.map! { |ivar| ivar.to_sym }
    end
    ivars = (instance_variables - excluded_ivars)
  elsif included_ivars = opts[:include]
    if is_ruby19
      included_ivars.map! { |ivar| ivar.to_sym }
    end
    ivars = included_ivars
  else
    raise ArgumentError, "unknown arg: #{opts.inspect}"
  end

  ivars.map! { |ivar| "#{ivar}=#{instance_variable_get(ivar).inspect}" }
  '#<%s:0x%s %s>' % [self.class.name, self.hash.to_s(16), ivars.join(" ")]
end