Module: Attributes

Included in:
Block, Day
Defined in:
lib/attributes.rb

Overview

Provides ActiveModel-like initializer.

Examples:

Initializing a class with setters it responds to


class Dog
  include Attributes
  attr_accessor :name, :age
end

dog = Dog.new :name => "foo", :age => 5
dog.name # => "foo"
dog.age  # => 5

Instance Method Summary collapse

Instance Method Details

#initialize(attributes = {}) ⇒ Object


14
15
16
17
18
# File 'lib/attributes.rb', line 14

def initialize(attributes = {})
  attributes.each do |k, v|
    send("#{k}=", v) if respond_to? k
  end
end