Class: RubyReportable::Sandbox
- Inherits:
-
Object
- Object
- RubyReportable::Sandbox
- Defined in:
- lib/ruby_reportable/sandbox.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #build(base, block) ⇒ Object
- #define(key, value) ⇒ Object
-
#initialize(_methods = {}) ⇒ Sandbox
constructor
A new instance of Sandbox.
- #metaclass ⇒ Object
Constructor Details
#initialize(_methods = {}) ⇒ Sandbox
Returns a new instance of Sandbox.
7 8 9 10 11 12 13 |
# File 'lib/ruby_reportable/sandbox.rb', line 7 def initialize(_methods = {}) @values = {} _methods.map do |key, value| define(key, value) end end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/ruby_reportable/sandbox.rb', line 20 def [](key) @values[key] end |
#[]=(key, value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/ruby_reportable/sandbox.rb', line 24 def []=(key, value) if value.is_a?(Proc) @values[key] = value.call else @values[key] = value end end |
#build(base, block) ⇒ Object
15 16 17 18 |
# File 'lib/ruby_reportable/sandbox.rb', line 15 def build(base, block) @values[base] = instance_eval(&block) self end |
#define(key, value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_reportable/sandbox.rb', line 32 def define(key, value) if self.class.respond_to?(:define_singleton_method) define_singleton_method(key) do if value.is_a?(Proc) @values[key] ||= value.call else @values[key] ||= value end end else .send(:define_method, key, Proc.new do if value.is_a?(Proc) @values[key] ||= value.call else @values[key] ||= value end end) end end |
#metaclass ⇒ Object
3 4 5 |
# File 'lib/ruby_reportable/sandbox.rb', line 3 def class << self; self; end end |