lib/core/facets/hash/update.rb in facets-2.4.3 vs lib/core/facets/hash/update.rb in facets-2.4.4
- old
+ new
@@ -1,20 +1,9 @@
+require 'facets/hash/op_push' # for backward compatibility
+
class Hash
- # Can be used like update, or passed
- # as two-element [key,value] array.
- #
- # CREDIT: Trans
-
- def <<(other)
- if other.respond_to?(:to_ary)
- self.store(*other)
- else
- update(other)
- end
- end
-
# Iterates through each pair and updates a the hash
# in place. This is formally equivalent to #mash!
# But does not use #mash to accomplish the task.
# Hence #update_each is probably a touch faster.
#
@@ -70,6 +59,23 @@
end
self
end
end
+
+
+=begin :spec:
+
+require 'quarry/spec'
+
+Quarry.specification "Hash" do
+
+ demonstrate "<<" do
+ h = {}
+ (h << [:a,1]).assert == h
+ h[:a].assert == 1
+ end
+
+end
+
+=end