Class: SuperSettings::Context::Current
- Inherits:
-
Object
- Object
- SuperSettings::Context::Current
- Defined in:
- lib/super_settings/context/current.rb
Overview
Current context for maintaining consistent setting values and random numbers within a specific execution context.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a value from the context.
-
#[]=(key, value) ⇒ Object
Set a value in the context.
-
#delete(key) ⇒ Object
Delete a value from the context.
-
#include?(key) ⇒ Boolean
Check if the context includes a specific key.
-
#initialize ⇒ Current
constructor
A new instance of Current.
-
#rand(max = nil) ⇒ Integer, Float
Generate a consistent random number for this context.
Constructor Details
#initialize ⇒ Current
Returns a new instance of Current.
8 9 10 11 |
# File 'lib/super_settings/context/current.rb', line 8 def initialize @context = {} @seed = nil end |
Instance Method Details
#[](key) ⇒ Object
Get a value from the context.
25 26 27 |
# File 'lib/super_settings/context/current.rb', line 25 def [](key) @context[key] end |
#[]=(key, value) ⇒ Object
Set a value in the context.
34 35 36 |
# File 'lib/super_settings/context/current.rb', line 34 def []=(key, value) @context[key] = value end |
#delete(key) ⇒ Object
Delete a value from the context.
42 43 44 |
# File 'lib/super_settings/context/current.rb', line 42 def delete(key) @context.delete(key) end |
#include?(key) ⇒ Boolean
Check if the context includes a specific key.
17 18 19 |
# File 'lib/super_settings/context/current.rb', line 17 def include?(key) @context.include?(key) end |
#rand(max = nil) ⇒ Integer, Float
Generate a consistent random number for this context.
50 51 52 53 |
# File 'lib/super_settings/context/current.rb', line 50 def rand(max = nil) @seed ||= Random.new_seed Random.new(@seed).rand(max || 1.0) end |