Sha256: 76ee027396214c8daf400bef046744abb55bb06d611a78b275d9537b00b8d7c9

Contents?: true

Size: 873 Bytes

Versions: 26

Compression:

Stored size: 873 Bytes

Contents

# encoding: utf-8

# HashContext
class HashContext
  attr_reader :receiver
  def initialize(receiver)
    @receiver = receiver
  end

  def method_missing(method_name, *args , &block)
    result = nil
    if args.size > 0
      receiver.reduce({}) do |ret, (key, value)|
        value = value.send method_name, *args
        ret[key] = value
        ret
      end
    else
      receiver.reduce({}) do |ret, (key , value)|
        value = value.send method_name
        ret[key] = value
        ret
      end
    end
  end

  def to_h
    @receiver
  end
end

# Hash
class Hash
  # return HashContext for each execute
  #
  # === Example
  #
  #   h = {key1: "value1", key2: "value2"}
  #   h.>>.upcase # => {key1: "VALUE1", key2: "VALUE2"}
  #   h.>>.+('_hoge') # => {key1: "value1_hoge", key2: "value2_hoge"}
  #
  def >>(dummy = nil)
    HashContext.new(self)
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.149 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.148 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.147 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.146 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.145 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.144 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.143 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.142 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.141 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.140 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.139 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.138 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.137 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.136 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.135 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.134 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.133 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.132 lib/open_classes/hash/gte_gte.rb
tbpgr_utils-0.0.131 lib/open_classes/hash/gte_gte.rb