lib/active_object/hash.rb in active_object-1.0.6 vs lib/active_object/hash.rb in active_object-1.0.7

- old
+ new

@@ -12,17 +12,17 @@ end end unless defined?(Rails) def compact - select { |k,v| !v.nil? } + select { |k, v| !v.nil? } end end unless defined?(Rails) def compact! - reject! { |k,v| v.nil? } + reject! { |k, v| v.nil? } end end unless defined?(Rails) def deep_merge(other_hash, &block) @@ -72,22 +72,22 @@ def only(*keys) dup.only!(*keys) end - def only!(*args) + def only!(*keys) hash = {} - args.each {|k| hash[k] = self[k] if self.has_key?(k) } - hash + keys.each { |k| hash[k] = self[k] if self.has_key?(k) } + replace(hash) end - def rename_keys(*args) - dup.rename_keys!(*args) + def rename_keys(*keys) + dup.rename_keys!(*keys) end - def rename_keys!(*args) - keys = Hash[*args.flatten] + def rename_keys!(*keys) + keys = Hash[*keys.flatten] keys.each { |k, v| self[v] = delete(k) if self[k] } self end unless defined?(Rails) @@ -127,34 +127,34 @@ end end unless defined?(Rails) def stringify_keys! - inject({}) do |options,(k,v)| + inject({}) do |options,(k, v)| options[k.to_s] = v options end end end def strip - select { |k,v| !v.blank? } + select { |k, v| !v.blank? } end def strip! - reject! { |k,v| v.blank? } + reject! { |k, v| v.blank? } end unless defined?(Rails) def symbolize_keys dup.symbolize_keys! end end unless defined?(Rails) def symbolize_keys! - inject({}) do |options, (k,v)| + inject({}) do |options, (k, v)| options[(k.to_sym rescue k) || k] = v options end end end @@ -162,11 +162,11 @@ def symbolize_and_underscore_keys dup.symbolize_and_underscore_keys! end def symbolize_and_underscore_keys! - inject({}) do |options, (k,v)| + inject({}) do |options, (k, v)| options[(k.to_s.gsub(" ", "_").underscore.to_sym rescue k) || k] = v options end end @@ -191,10 +191,10 @@ end unless defined?(Rails) def transform_values!(&block) return(enum_for(:transform_values!)) unless block_given? - each { |k,v| self[k] = yield(v) } + each { |k, v| self[k] = yield(v) } end end end \ No newline at end of file