Sha256: cf2506e4fb0bf5abc4bdf83cbe801a8d8f6f1a72d6df98864e08c86392a5b4d5

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

= Association

An Association is a class for creating simple pairings.

    require 'hashery/association'

An Association can bew created through the usual means 
of instantiation.

    Association.new(:a, :b)

Or the shortcut method #>> can be used in most cases.

    :x >> :z

An association provides two methods to access its content, #index and #value.

    a = 'foo' >> 'bar'

    a.index.assert == 'foo'
    a.value.assert == 'bar'

Associations can be used to create ordered-hashes via normal
arrays.

    keys = []
    vals = []

    ohash = [ 'A' >> '3', 'B' >> '2', 'C' >> '1' ]

    ohash.each{ |k,v| keys << k ; vals << v }

    keys.assert == ['A','B','C']
    vals.assert == ['3','2','1']


Becuase Associations are objects in themselves more complex
collections can also be created.

    complex = [
      'parent' >> 'child',
      'childless',
      'another_parent' >> [
        'subchildless',
        'subparent' >> 'subchild'
      ]
    ]

An experimental feature of Association keeps a cache of all defined associations.

    o = Object.new
    o >> :a
    o >> :b
    o >> :c

    o.associations.assert == [:a, :b, :c]

However this feature will probably be deprecated.

Version data entries

6 entries across 5 versions & 2 rubygems

Version Path
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.4.0/gems/hashery-2.1.2/demo/10_association.rdoc
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.5.0/gems/hashery-2.1.2/demo/10_association.rdoc
hashery-2.1.2 demo/10_association.rdoc
hashery-2.1.1 demo/10_association.rdoc
hashery-1.5.0 qed/05_association.rdoc
hashery-1.4.0 qed/05_association.rdoc