Ruby on Rails has special under-the-hood magic that will patch four methods onto your models for each enum value you specify. That means if you specify an enum with 3 values, Rails gives you 12 magic methods associated with names based on these values.
Take the example above:
def Invoice < ActiveResource enum status: [:pending: 'pending', in_progress: 'in_progress', finished: 'finished']
Rails will put 4 methods for each enum:
IN this example
invoice represents an instance of a since invoice and
Invoice represents the Invoice class.
|for our |
|Bang (!)||Tells the object to become that status.|
|Interrogative (?)||Asks the object if it is in that status|
|Scope (…)||When used on the class, provides a scope that will get all of the object in this state|
|Negative scope (|
Remember, the scopes are ActiveRecord chain-able scopes, so they can be used in conjunction with other valid scopes too. (
Invoices.pending.not_paid for example).