Sha256: b53b82df210bbdeaeeed3eca9e0a825efcc1b0c403d6970087d5cad35614e985

Contents?: true

Size: 736 Bytes

Versions: 15

Compression:

Stored size: 736 Bytes

Contents

require 'facet/core/kernel/instance'

class OpenStruct

  # Intercepts some methods to apply to the inner table
  # rather then be defined as part of the open members.
  # As with Kernel#instance all other methods are passed
  # on to the Kernel binding.
  #
  #   o = OpenStruct.new
  #   o.a = 1
  #   o.b = 2
  #   o.instance.each { |k, v| puts "#{k} #{v}" }
  #
  # produces
  # 
  #   a 1
  #   b 2   
  #
  # Methods supported:
  #   store, fetch, merge, update, each, key?
  #

  def instance
    Functor.new { |op, *args|
      case op
      when  :[], :[]=, :store, :fetch, :merge, :update,
            :each, :key?
        @table.send(op,*args)
      else
        super(op,*args)  # send(op,*args)
      end
    }
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
facets-1.2.1 lib/facets/core/ostruct/instance.rb
facets-1.3.0 lib/facets/core/ostruct/instance.rb
facets-1.3.2 lib/facets/core/ostruct/instance.rb
facets-1.3.3 lib/facets/core/ostruct/instance.rb
facets-1.3.1 lib/facets/core/ostruct/instance.rb
facets-1.4.0 lib/facets/core/ostruct/instance.rb
facets-1.4.2 lib/facets/core/ostruct/instance.rb
facets-1.4.1 lib/facets/core/ostruct/instance.rb
facets-1.4.3 lib/facets/core/ostruct/instance.rb
facets-1.4.4 lib/facets/core/ostruct/instance.rb
facets-1.4.5 lib/facets/core/ostruct/instance.rb
facets-1.7.0 lib/facets/core/ostruct/instance.rb
facets-1.7.30 lib/facets/core/ostruct/instance.rb
facets-1.7.38 lib/facets/core/ostruct/instance.rb
facets-1.7.46 lib/facets/core/ostruct/instance.rb