Module: Gamefic::Scriptable::Proxies

Included in:
Narrative, Entities, Queries
Defined in:
lib/gamefic/scriptable/proxies.rb

Overview

Methods for referencing entities from proxies.

Instance Method Summary collapse

Instance Method Details

#unproxy(object) ⇒ Object

Convert a proxy into its referenced entity.

This method can receive any kind of object. If it’s a proxy, its entity will be returned. If it’s an array, each of its elements will be unproxied. If it’s a hash, each of its values will be unproxied. Any other object will be returned unchanged.

Parameters:

  • object (Object)

Returns:

  • (Object)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gamefic/scriptable/proxies.rb', line 17

def unproxy object
  case object
  when Proxy, Proxy::Base
    object.fetch self
  when Array
    object.map { |obj| unproxy obj }
  when Hash
    object.transform_values { |val| unproxy val }
  else
    object
  end
end