Module: RTM::Sugar::Association::HashAccess

Defined in:
rtm/lib/rtm/sugar/association/hash_access.rb,
rtm/spec/rtm/sugar/association/hash_access_spec.rb

Overview

This module implements methods for Hash-like access in Associations.

Instance Method Summary

Instance Method Details

- (Object) [](type = :any)

Returns all Roles of this Association.

If type is given, returns the Roles of this Association whose Role type match type. Type may be a topic reference.

The result may be empty.

:call-seq:

  [] -> Array of Roles
  [type] -> Array of Roles


21
22
23
24
25
26
27
28
29
30
# File 'rtm/lib/rtm/sugar/association/hash_access.rb', line 21

def [](type=:any)
  return getRoles.to_a if type == :any
  return getRoles.to_a unless type
  type = topic_map.get(type)
  if type
    return getRoles(type).to_a
  else
    return []
  end
end

- (Object) []=(type, player)

Creates a new Role in this Association where type specifies the Role type and player the associated Role player. Type and player may each be a topic reference.

:call-seq:

  [type]= player

TODO Issue #919



41
42
43
# File 'rtm/lib/rtm/sugar/association/hash_access.rb', line 41

def []=(type,player)
  create_role(type,player)
end