Class: Hash
Instance Method Summary collapse
- #filter(*keys) ⇒ Object
- #list(*keys) ⇒ Object
- #match(regexp) ⇒ Object
- #to_obj ⇒ Object
- #without(*args) ⇒ Object
Instance Method Details
#filter(*keys) ⇒ Object
139 140 141 142 143 |
# File 'lib/homeschool.rb', line 139 def filter(*keys) keys.inject({}) do |h, key| h[key] = self[key] if has_key?(key); h end end |
#list(*keys) ⇒ Object
151 152 153 |
# File 'lib/homeschool.rb', line 151 def list(*keys) keys.collect &method(:[]) end |
#match(regexp) ⇒ Object
145 146 147 148 149 |
# File 'lib/homeschool.rb', line 145 def match(regexp) inject({}) do |h, (key, value)| h[key] = value if key.to_s =~ regexp; h end end |
#to_obj ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/homeschool.rb', line 125 def to_obj returning Object.new do |obj| each do |key, value| obj. key.to_sym do value end end end end |
#without(*args) ⇒ Object
133 134 135 136 137 |
# File 'lib/homeschool.rb', line 133 def without(*args) reject do |k, v| args.include?(k) end end |