Sha256: aee6dac7990153564d363722ed4cf511ef07d9343f73513f9e74c856df92ac6c

Contents?: true

Size: 824 Bytes

Versions: 20

Compression:

Stored size: 824 Bytes

Contents

module RestCore; end
class RestCore::Clash
  Empty = Hash.new(&(l = lambda{|_,_|Hash.new(&l).freeze})).freeze

  attr_accessor :data
  def initialize data
    self.data = data
  end

  def [] k
    if data.key?(k)
      convert(data[k])
    else
      Empty
    end
  end

  def == rhs
    if rhs.kind_of?(RestCore::Clash)
      data == rhs.data
    else
      data == rhs
    end
  end

  private
  def convert value
    case value
    when Hash
      RestCore::Clash.new(value)
    when Array
      value.map{ |ele| convert(ele) }
    else
      value
    end
  end

  def respond_to_missing? msg, include_private=false
    data.respond_to?(msg, include_private)
  end

  def method_missing msg, *args, &block
    if data.respond_to?(msg)
      data.public_send(msg, *args, &block)
    else
      super
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rest-core-3.6.0 lib/rest-core/util/clash.rb
rest-core-3.5.92 lib/rest-core/util/clash.rb
rest-core-3.5.91 lib/rest-core/util/clash.rb
rest-core-3.5.9 lib/rest-core/util/clash.rb
rest-core-3.5.8 lib/rest-core/util/clash.rb
rest-core-3.5.7 lib/rest-core/util/clash.rb
rest-core-3.5.6 lib/rest-core/util/clash.rb
rest-core-3.5.5 lib/rest-core/util/clash.rb
rest-core-3.5.4 lib/rest-core/util/clash.rb
rest-core-3.5.3 lib/rest-core/util/clash.rb
rest-core-3.5.2 lib/rest-core/util/clash.rb
rest-core-3.5.1 lib/rest-core/util/clash.rb
rest-core-3.5.0 lib/rest-core/util/clash.rb
rest-core-3.4.1 lib/rest-core/util/clash.rb
rest-core-3.4.0 lib/rest-core/util/clash.rb
rest-core-3.3.3 lib/rest-core/util/clash.rb
rest-core-3.3.2 lib/rest-core/util/clash.rb
rest-core-3.3.1 lib/rest-core/util/clash.rb
rest-core-3.3.0 lib/rest-core/util/clash.rb
rest-core-3.2.0 lib/rest-core/util/clash.rb