Skip to content

Instantly share code, notes, and snippets.

@slavakisel
Created June 7, 2018 08:36
Show Gist options
  • Save slavakisel/6f04743d2318904b1b17e03d806758ae to your computer and use it in GitHub Desktop.
Save slavakisel/6f04743d2318904b1b17e03d806758ae to your computer and use it in GitHub Desktop.
module Inspector
extend ActiveSupport::Concern
included do
def inspect
inspection = @attributes ? inspected_attributes : "not initialized"
"#<#{self.class} #{inspection}>"
end
def inspected_attributes
self.class.column_names
.select { |c| c.exclude?(*exclude_from_inspect) }
.collect { |name| "#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name) }
.compact
.join(", ")
end
def exclude_from_inspect
[]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment