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

Defined in:
lib/rtm/sugar/association/hash_access.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#[](type = :any) ⇒ Object

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 '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

#[]=(type, player) ⇒ Object

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 'lib/rtm/sugar/association/hash_access.rb', line 41

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