More changes around 1.9 hash syntax

Added missing space in previous hash related commit
This commit is contained in:
AvnerCohen 2012-10-21 22:28:50 +02:00
parent 40b0cecea2
commit 7fbb21dc80
2 changed files with 4 additions and 4 deletions

View File

@ -18,7 +18,7 @@ class Array
# end
#
# options(1, 2) # => {}
# options(1, 2, a: :b) # => {:a=>:b}
# options(1, 2, a: :b) # => {a: :b}
def extract_options!
if last.is_a?(Hash) && last.extractable_options?
pop

View File

@ -4,10 +4,10 @@ class Hash
# h1 = { x: { y: [4,5,6] }, z: [7,8,9] }
# h2 = { x: { y: [7,8,9] }, z: 'xyz' }
#
# h1.deep_merge(h2) #=> {:x => {:y => [7, 8, 9]}, :z => "xyz"}
# h2.deep_merge(h1) #=> {:x => {:y => [4, 5, 6]}, :z => [7, 8, 9]}
# h1.deep_merge(h2) #=> {x: {y: [7, 8, 9]}, z: "xyz"}
# h2.deep_merge(h1) #=> {x: {y: [4, 5, 6]}, z: [7, 8, 9]}
# h1.deep_merge(h2) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
# #=> {:x => {:y => [4, 5, 6, 7, 8, 9]}, :z => [7, 8, 9, "xyz"]}
# #=> {x: {y: [4, 5, 6, 7, 8, 9]}, z: [7, 8, 9, "xyz"]}
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end