Module: ActsAsDynamic::Base
- Defined in:
- lib/acts_as_dynamic/base.rb
Overview
Base
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Object
Builder.
-
#metaclass ⇒ Object
Metaclass.
-
#method_missing(attribute, value = "") ⇒ Object
Method missing.
-
#new_record? ⇒ Boolean
New record?.
-
#persisted? ⇒ Boolean
Persisted?.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attribute, value = "") ⇒ Object
Method missing
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/acts_as_dynamic/base.rb', line 25 def method_missing(attribute, value = "") # Assignation? if attribute.to_s["="] # Adding attribute .send :attr_accessor, attribute.to_s[/[^=]+/] self.send attribute, value else nil end end |
Instance Method Details
#initialize(args = {}) ⇒ Object
Builder
10 11 12 13 14 15 |
# File 'lib/acts_as_dynamic/base.rb', line 10 def initialize args = {} (args || {}).each_pair do |attribute, value| self.send "#{attribute}=", value end self end |
#metaclass ⇒ Object
Metaclass
18 19 20 21 22 |
# File 'lib/acts_as_dynamic/base.rb', line 18 def class << self self end end |
#new_record? ⇒ Boolean
New record?
37 38 39 |
# File 'lib/acts_as_dynamic/base.rb', line 37 def new_record? true end |
#persisted? ⇒ Boolean
Persisted?
42 43 44 |
# File 'lib/acts_as_dynamic/base.rb', line 42 def persisted? false end |