public Method

Base.attributes(options = nil)

Returns a hash of all the attributes with their names as keys and clones of their objects as values.

Source Code

# File active_record/base.rb, line 2126
def attributes(options = nil)
  attributes = clone_attributes :read_attribute

  if options.nil?
    attributes
  else
    if except = options[:except]
      except = Array(except).collect { |attribute| attribute.to_s }
      except.each { |attribute_name| attributes.delete(attribute_name) }
      attributes
    elsif only = options[:only]
      only = Array(only).collect { |attribute| attribute.to_s }
      attributes.delete_if { |key, value| !only.include?(key) }
      attributes
    else
      raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"
    end
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.