Class: Hash
Overview
Hash extentions
Instance Method Summary collapse
- #extract!(&block) ⇒ Object
- #flush_out(prev = "", post = "") ⇒ Object
- #old_select ⇒ Object
- #safe_merge(other_hash) ⇒ Object
- #safe_merge!(other_hash) ⇒ Object
- #select(&block) ⇒ Object
- #to_os ⇒ Object
Instance Method Details
#extract!(&block) ⇒ Object
10 11 12 13 14 |
# File 'lib/poolparty/core/hash.rb', line 10 def extract!(&block) o = select(&block) o.keys.each {|k| self.delete(k) } o end |
#flush_out(prev = "", post = "") ⇒ Object
21 22 23 |
# File 'lib/poolparty/core/hash.rb', line 21 def flush_out(prev="", post="") map {|k,v| "#{prev}#{k} => #{v.to_option_string}#{post}"} end |
#old_select ⇒ Object
5 |
# File 'lib/poolparty/core/hash.rb', line 5 alias :old_select :select |
#safe_merge(other_hash) ⇒ Object
15 16 17 |
# File 'lib/poolparty/core/hash.rb', line 15 def safe_merge(other_hash) merge(other_hash.delete_if {|k,v| has_key?(k) }) end |
#safe_merge!(other_hash) ⇒ Object
18 19 20 |
# File 'lib/poolparty/core/hash.rb', line 18 def safe_merge!(other_hash) merge!(other_hash.delete_if {|k,v| has_key?(k) && !v.nil? }) end |
#select(&block) ⇒ Object
7 8 9 |
# File 'lib/poolparty/core/hash.rb', line 7 def select(&block) Hash[*self.old_select(&block).inject([]){|res,(k,v)| res << k << v}] end |
#to_os ⇒ Object
24 25 26 27 28 |
# File 'lib/poolparty/core/hash.rb', line 24 def to_os m={} each {|k,v| m[k] = v.to_os } MyOpenStruct.new(m) end |