Sha256: 9bcedad786e295f6253e47739f1ac3856311e117124f060f3bd7dd407104d5bb

Contents?: true

Size: 684 Bytes

Versions: 14

Compression:

Stored size: 684 Bytes

Contents

class Hash
  # Returns a new hash with the results of running +block+ once for every value.
  # The keys are unchanged.
  #
  #   { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 }
  #   # => { a: 2, b: 4, c: 6 }
  def transform_values
    return enum_for(:transform_values) unless block_given?
    result = self.class.new
    each do |key, value|
      result[key] = yield(value)
    end
    result
  end unless method_defined? :transform_values

  # Destructive +transform_values+
  def transform_values!
    return enum_for(:transform_values!) unless block_given?
    each do |key, value|
      self[key] = yield(value)
    end
  end unless method_defined? :transform_values!
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
activesupport-4.2.11.3 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.11.2 lib/active_support/core_ext/hash/transform_values.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/hash/transform_values.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.11.1 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.11 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.10 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.10.rc1 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.9 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.9.rc2 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.9.rc1 lib/active_support/core_ext/hash/transform_values.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-4.2.8/lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.8 lib/active_support/core_ext/hash/transform_values.rb
activesupport-4.2.8.rc1 lib/active_support/core_ext/hash/transform_values.rb