mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Improve conditional in awesome_object_data
This commit is contained in:
parent
570c5f26db
commit
704a813547
1 changed files with 10 additions and 6 deletions
|
@ -58,6 +58,12 @@ module AwesomePrint
|
|||
|
||||
private
|
||||
|
||||
# Check whether a variable_name is a method or ivar
|
||||
#------------------------------------------------------------------------------
|
||||
def valid_instance_var?(variable_name)
|
||||
variable_name.to_s.start_with?('@')
|
||||
end
|
||||
|
||||
# Catch all method to format an arbitrary object.
|
||||
#------------------------------------------------------------------------------
|
||||
def awesome_self(object, type)
|
||||
|
@ -158,15 +164,13 @@ module AwesomePrint
|
|||
end
|
||||
end
|
||||
indented do
|
||||
result = colorize(" = ", :hash)
|
||||
|
||||
if var.to_s.start_with?('@')
|
||||
result += @inspector.awesome(o.instance_variable_get(var))
|
||||
var_contents = if valid_instance_var?(var)
|
||||
o.instance_variable_get(var)
|
||||
else
|
||||
result += @inspector.awesome(o.send(var))
|
||||
o.send(var) # Enables handling of Struct attributes
|
||||
end
|
||||
|
||||
key << result
|
||||
key << colorize(" = ", :hash) + @inspector.awesome(var_contents)
|
||||
end
|
||||
end
|
||||
if @options[:multiline]
|
||||
|
|
Loading…
Add table
Reference in a new issue