Module: MagicAttributes
- Defined in:
- lib/mark_facets/ruby/magic_attributes.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
20
21
22
|
# File 'lib/mark_facets/ruby/magic_attributes.rb', line 20
def method_missing(sym, *args, &block)
self.attributes.send(sym, *args)
end
|
Class Method Details
.included(klass) ⇒ Object
5
6
7
8
9
|
# File 'lib/mark_facets/ruby/magic_attributes.rb', line 5
def included(klass)
klass.class_eval do
attr_accessor :attributes
end
end
|
Instance Method Details
#initialize(attributes = {}) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/mark_facets/ruby/magic_attributes.rb', line 13
def initialize(attributes = {})
self.attributes = (attributes || {}).to_mash
self.attributes.each do |k, v|
self.send("#{k}=", v) if self.respond_to?("#{k}=")
end
end
|