module ActiveModel::Serialization
def serializable_hash(options = nil)
def serializable_hash(options = nil) options ||= {} only = Array.wrap(options[:only]).map(&:to_s) except = Array.wrap(options[:except]).map(&:to_s) attribute_names = attributes.keys.sort if only.any? attribute_names &= only elsif except.any? attribute_names -= except end method_names = Array.wrap(options[:methods]).inject([]) do |methods, name| methods << name if respond_to?(name.to_s) methods end (attribute_names + method_names).inject({}) { |hash, name| hash[name] = send(name) hash } end