Module: Enumerize::Predicates

Defined in:
lib/enumerize/predicates.rb

Overview

Predicate methods.

Basic usage:

class User
  extend Enumerize
  enumerize :sex, in: %w(male female), predicates: true
end

user = User.new

user.male?   # => false
user.female? # => false

user.sex = 'male'

user.male?   # => true
user.female? # => false

Using prefix:

class User
  extend Enumerize
  enumerize :sex, in: %w(male female), predicates: { prefix: true }
end

user = User.new
user.sex = 'female'
user.sex_female? # => true

Use only and except options to specify what values create predicate methods for.

Defined Under Namespace

Classes: Builder

Instance Method Summary collapse

Instance Method Details

#enumerize(name, options = {}) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/enumerize/predicates.rb', line 39

def enumerize(name, options={})
  super

  if options[:predicates]
    Builder.new(enumerized_attributes[name], options[:predicates]).build(_enumerize_module)
  end
end