lib/extlib/mash.rb in extlib-0.9.6 vs lib/extlib/mash.rb in extlib-0.9.7
- old
+ new
@@ -94,10 +94,21 @@
# The key to delete from the mash.\
def delete(key)
super(convert_key(key))
end
+ # @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
+ #
+ # @return <Mash> A new mash without the selected keys.
+ #
+ # @example
+ # { :one => 1, :two => 2, :three => 3 }.except(:one)
+ # #=> { "two" => 2, "three" => 3 }
+ def except(*keys)
+ super(*keys.map {|k| convert_key(k)})
+ end
+
# Used to provide the same interface as Hash.
#
# @return <Mash> This mash unchanged.
def stringify_keys!; self end
@@ -124,15 +135,14 @@
# The converted value. A Hash or an Array of hashes, will be converted to
# their Mash equivalents.
#
# @api private
def convert_value(value)
- case value
- when Hash
+ if value.class == Hash
value.to_mash
- when Array
+ elsif value.is_a?(Array)
value.collect { |e| convert_value(e) }
- else
- value
+ else
+ value
end
end
end
\ No newline at end of file