Class: CuteKV::Associations::Symmetry
- Inherits:
-
Object
- Object
- CuteKV::Associations::Symmetry
- Defined in:
- lib/cute_kv/associations.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(asso = {}) ⇒ Symmetry
constructor
A new instance of Symmetry.
- #mirror(object) ⇒ Object
Constructor Details
#initialize(asso = {}) ⇒ Symmetry
Returns a new instance of Symmetry.
13 14 15 16 |
# File 'lib/cute_kv/associations.rb', line 13 def initialize(asso={}) @asso_string = parse(asso) @assos = @asso_string.split("#") end |
Instance Method Details
#each ⇒ Object
25 26 27 28 |
# File 'lib/cute_kv/associations.rb', line 25 def each asso = [[@assos[0].constantize, @assos[1].to_sym ],[@assos[-1].constantize, @assos[-2].to_sym]].uniq asso.each {|a| yield a[0], a[-1]} end |
#mirror(object) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/cute_kv/associations.rb', line 18 def mirror(object) m_o = @assos[@assos.size - 1 - @assos.index(object.to_s)] m_o = m_o.constantize if object.is_a? Class m_o = m_o.to_sym if object.is_a? Symbol m_o end |