Class: SimpleMapper::Collection::Hash

Inherits:
Hash
  • Object
show all
Includes:
CommonMethods
Defined in:
lib/simple_mapper/collection.rb

Instance Attribute Summary

Attributes included from CommonMethods

#attribute, #change_tracking

Instance Method Summary collapse

Methods included from CommonMethods

#[]=, #build, #changed_members, #member_changed!, #simple_mapper_changes

Constructor Details

#initialize(hash = {}) ⇒ Hash

Returns a new instance of Hash.



53
54
55
# File 'lib/simple_mapper/collection.rb', line 53

def initialize(hash = {})
  super(hash)
end

Instance Method Details

#delete(key) ⇒ Object



57
58
59
60
# File 'lib/simple_mapper/collection.rb', line 57

def delete(key)
  member_changed!(key, nil)
  super(key)
end

#delete_ifObject



73
74
75
76
# File 'lib/simple_mapper/collection.rb', line 73

def delete_if
  reject! {|k, v| yield(k, v)}
  self
end

#is_member?(key) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/simple_mapper/collection.rb', line 49

def is_member?(key)
  key? key
end

#reject!Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/simple_mapper/collection.rb', line 62

def reject!
  changed = false
  each do |key, val|
    if yield(key, val)
      changed = true
      delete(key)
    end
  end
  changed ? self : nil
end