method

attr_accessor_with_default

Importance_1
Ruby on Rails latest stable (v2.2.1) - 0 notes - Class: Module
  • v1.0.0
  • v1.1.0
  • v1.1.1
  • v1.1.2
  • v1.1.3
  • v1.1.4
  • v1.1.5
  • v1.1.6
  • v1.2.0
  • v1.2.1
  • v1.2.2
  • v1.2.3
  • v1.2.4
  • v1.2.5
  • v1.2.6
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.0.3
  • 2.1.0 (0)
  • 2.2.1 (0)
  • What's this?
attr_accessor_with_default(sym, default = nil, &block) public

Declare an attribute accessor with an initial default return value.

To give attribute :age the initial value 25:

  class Person
    attr_accessor_with_default :age, 25
  end

  some_person.age
  => 25
  some_person.age = 26
  some_person.age
  => 26

To give attribute :element_name a dynamic default value, evaluated in scope of self:

  attr_accessor_with_default(:element_name) { name.underscore }
Show source
Register or log in to add new notes.