Module: Configurable

Included in:
Steamworks::Configure
Defined in:
lib/steamworks/core_ext/configurable.rb

Overview

Instance Method Summary collapse

Instance Method Details

#set(option, value = (not_set = true), read_only: false) ⇒ nil

Sets an option to the given value.

Parameters:

  • option (Symbol)

    the name of config

  • value (Object) (defaults to: (not_set = true))

    value to the name

  • read_only (Boolean) (defaults to: false)

    Generate option= method or not

Returns:

  • (nil)

    nil

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/steamworks/core_ext/configurable.rb', line 11

def set(option, value = (not_set = true), read_only: false)
  raise ArgumentError if not_set

  setter = proc { |val| set option, val }
  getter = proc { value }

  define_singleton("#{option}=", setter) unless read_only
  define_singleton(option, getter)
  define_singleton("#{option}?", "!!#{option}") unless method_defined? "#{option}?"

  self
end