instance method read_attribute_for_serialization

Ruby on Rails edge

Since edge

Signature

read_attribute_for_serialization(key)

Hook method defining how an attribute value should be retrieved for serialization. By default this is assumed to be an instance named after the attribute. Override this method in subclasses should you need to retrieve the value for a given attribute differently:

class MyClass
  include ActiveModel::Serialization

  def initialize(data = {})
    @data = data
  end

  def read_attribute_for_serialization(key)
    @data[key]
  end
end

Parameters

key req
Source
# File activemodel/lib/active_model/serialization.rb, line 167
    def read_attribute_for_serialization(key)
      send(key)
    end

Defined in activemodel/lib/active_model/serialization.rb line 167 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveModel::Serialization

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close