module SnakyHash::Serializer::BackportedInstanceMethods
Provides backported methods for older Ruby versions
Public Instance Methods
transform_values() { |value| ... }
click to toggle source
:nocov: Transforms values of a hash using the given block
@yield [Object] block to transform each value @return [Hash] new hash with transformed values @return [Enumerator] if no block given @note This will be run in CI on Ruby 2.3, but we only collect coverage from current Ruby
Rails <= 5.2 had a transform_values method, which was added to Ruby in version 2.4. This method is a backport of that original Rails method for Ruby 2.2 and 2.3.
# File lib/snaky_hash/serializer.rb 99 def transform_values(&block) 100 return enum_for(:transform_values) { size } unless block_given? 101 return {} if empty? 102 result = self.class.new 103 each do |key, value| 104 result[key] = yield(value) 105 end 106 result 107 end