method
to_key
v8.0.0 -
Show latest stable
- Class:
ActiveModel::Conversion
to_key()public
Returns an Array of all key attributes if any of the attributes is set, whether or not the object is persisted. Returns nil if there are no key attributes.
class Person include ActiveModel::Conversion attr_accessor :id def initialize(id) @id = id end end person = Person.new(1) person.to_key # => [1]