{
    "mode": "ri",
    "parameter": "ActiveModel::Serialization",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/ri/ActiveModel%3A%3ASerialization/json",
    "generated": "2026-07-28T01:52:43Z",
    "sections": {
        "ActiveModel::Serialization": {
            "content": "(from /home/chedong/.local/share/rdoc)\n------------------------------------------------------------------------",
            "subsections": [
                {
                    "name": "Active Model Serialization",
                    "content": "Provides a basic serialization to a serializablehash for your objects.\n\nA minimal implementation could be:\n\nclass Person\ninclude ActiveModel::Serialization\n\nattraccessor :name\n\ndef attributes\n{'name' => nil}\nend\nend\n\nWhich would provide you with:\n\nperson = Person.new\nperson.serializablehash   # => {\"name\"=>nil}\nperson.name = \"Bob\"\nperson.serializablehash   # => {\"name\"=>\"Bob\"}\n\nAn attributes hash must be defined and should contain any attributes you\nneed to be serialized. Attributes must be strings, not symbols. When\ncalled, serializable hash will use instance methods that match the name\nof the attributes hash's keys. In order to override this behavior, take\na look at the private method readattributeforserialization.\n\nActiveModel::Serializers::JSON module automatically includes the\nActiveModel::Serialization module, so there is no need to explicitly\ninclude ActiveModel::Serialization.\n\nA minimal implementation including JSON would be:\n\nclass Person\ninclude ActiveModel::Serializers::JSON\n\nattraccessor :name\n\ndef attributes\n{'name' => nil}\nend\nend\n\nWhich would provide you with:\n\nperson = Person.new\nperson.serializablehash   # => {\"name\"=>nil}\nperson.asjson             # => {\"name\"=>nil}\nperson.tojson             # => \"{\\\"name\\\":null}\"\n\nperson.name = \"Bob\"\nperson.serializablehash   # => {\"name\"=>\"Bob\"}\nperson.asjson             # => {\"name\"=>\"Bob\"}\nperson.tojson             # => \"{\\\"name\\\":\\\"Bob\\\"}\"\n\nValid options are :only, :except, :methods and :include. The following\nare all valid examples:\n\nperson.serializablehash(only: 'name')\nperson.serializablehash(include: :address)\nperson.serializablehash(include: { address: { only: 'city' }})\n------------------------------------------------------------------------"
                }
            ]
        },
        "Instance methods:": {
            "content": "serializablehash\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}