Class: Shomen::Model::AbstractPrime
- Inherits:
-
Object
- Object
- Shomen::Model::AbstractPrime
- Defined in:
- lib/shomen/model/abstract.rb
Overview
Baseclass for all model classes.
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize(settings = {}) ⇒ AbstractPrime
constructor
A new instance of AbstractPrime.
- #to_h ⇒ Object
Constructor Details
#initialize(settings = {}) ⇒ AbstractPrime
Returns a new instance of AbstractPrime.
27 28 29 30 31 32 33 |
# File 'lib/shomen/model/abstract.rb', line 27 def initialize(settings={}) @table = {} settings.each do |k,v| s = "#{k}=".gsub('-','_') __send__(s,v) end end |
Class Method Details
.attr_accessor(name) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/shomen/model/abstract.rb', line 11 def self.attr_accessor(name) name = name.to_s define_method(name) do self[name] end define_method(name+'=') do |x| self[name] = x end end |
.type ⇒ Object
22 23 24 |
# File 'lib/shomen/model/abstract.rb', line 22 def self.type name.split('::').last.downcase end |
Instance Method Details
#[](k) ⇒ Object
36 37 38 |
# File 'lib/shomen/model/abstract.rb', line 36 def [](k) @table[k.to_s] end |
#[]=(k, v) ⇒ Object
41 42 43 |
# File 'lib/shomen/model/abstract.rb', line 41 def []=(k,v) @table[k.to_s] = v end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shomen/model/abstract.rb', line 46 def to_h t = {} @table.each do |k,v| if v.respond_to?(:to_h) t[k] = v.to_h else t[k] = v end end t end |