{
    "content": [
        {
            "type": "text",
            "text": "# ActiveRecord::Enum (ri)\n\n## Sections\n\n- **ActiveRecord::Enum**\n- **Instance methods:**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "ActiveRecord::Enum",
        "section": "",
        "mode": "ri",
        "summary": null,
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "ActiveRecord::Enum",
                "lines": 104,
                "subsections": []
            },
            {
                "name": "Instance methods:",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "ActiveRecord::Enum": {
                "content": "(from /home/chedong/.local/share/rdoc)\n------------------------------------------------------------------------\nDeclare an enum attribute where the values map to integers in the\ndatabase, but can be queried by name. Example:\n\nclass Conversation < ActiveRecord::Base\nenum status: [ :active, :archived ]\nend\n\n# conversation.update! status: 0\nconversation.active!\nconversation.active? # => true\nconversation.status  # => \"active\"\n\n# conversation.update! status: 1\nconversation.archived!\nconversation.archived? # => true\nconversation.status    # => \"archived\"\n\n# conversation.status = 1\nconversation.status = \"archived\"\n\nconversation.status = nil\nconversation.status.nil? # => true\nconversation.status      # => nil\n\nScopes based on the allowed values of the enum field will be provided as\nwell. With the above example:\n\nConversation.active\nConversation.notactive\nConversation.archived\nConversation.notarchived\n\nOf course, you can also query them directly if the scopes don't fit your\nneeds:\n\nConversation.where(status: [:active, :archived])\nConversation.where.not(status: :active)\n\nDefining scopes can be disabled by setting :scopes to false.\n\nclass Conversation < ActiveRecord::Base\nenum status: [ :active, :archived ], scopes: false\nend\n\nYou can set the default enum value by setting :default, like:\n\nclass Conversation < ActiveRecord::Base\nenum status: [ :active, :archived ], default: \"active\"\nend\n\nconversation = Conversation.new\nconversation.status # => \"active\"\n\nFinally, it's also possible to explicitly map the relation between\nattribute and database integer with a hash:\n\nclass Conversation < ActiveRecord::Base\nenum status: { active: 0, archived: 1 }\nend\n\nNote that when an array is used, the implicit mapping from the values to\ndatabase integers is derived from the order the values appear in the\narray. In the example, :active is mapped to 0 as it's the first element,\nand :archived is mapped to 1. In general, the i-th element is mapped to\ni-1 in the database.\n\nTherefore, once a value is added to the enum array, its position in the\narray must be maintained, and new values should only be added to the end\nof the array. To remove unused values, the explicit hash syntax should\nbe used.\n\nIn rare circumstances you might need to access the mapping directly. The\nmappings are exposed through a class method with the pluralized\nattribute name, which return the mapping in a HashWithIndifferentAccess:\n\nConversation.statuses[:active]    # => 0\nConversation.statuses[\"archived\"] # => 1\n\nUse that class method when you need to know the ordinal value of an\nenum. For example, you can use that when manually building SQL strings:\n\nConversation.where(\"status <> ?\", Conversation.statuses[:archived])\n\nYou can use the :prefix or :suffix options when you need to define\nmultiple enums with same values. If the passed value is true, the\nmethods are prefixed/suffixed with the name of the enum. It is also\npossible to supply a custom value:\n\nclass Conversation < ActiveRecord::Base\nenum status: [:active, :archived], suffix: true\nenum commentsstatus: [:active, :inactive], prefix: :comments\nend\n\nWith the above example, the bang and predicate methods along with the\nassociated scopes are now prefixed and/or suffixed accordingly:\n\nconversation.activestatus!\nconversation.archivedstatus? # => false\n\nconversation.commentsinactive!\nconversation.commentsactive? # => false\n------------------------------------------------------------------------",
                "subsections": []
            },
            "Instance methods:": {
                "content": "enum\n",
                "subsections": []
            }
        }
    }
}