Class: Spade::Runtime::Exports
- Inherits:
-
Object
- Object
- Spade::Runtime::Exports
- Defined in:
- lib/spade/runtime/exports.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(ctx) ⇒ Exports
constructor
A new instance of Exports.
Constructor Details
#initialize(ctx) ⇒ Exports
Returns a new instance of Exports.
25 26 27 |
# File 'lib/spade/runtime/exports.rb', line 25 def initialize(ctx) @context = ctx end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
23 24 25 |
# File 'lib/spade/runtime/exports.rb', line 23 def context @context end |
Instance Method Details
#[](name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/spade/runtime/exports.rb', line 29 def [](name) begin if self.class.const_defined?(name) ret = self.class.const_get(name) # If we are returning a class, create a custom subclass the first # time that also exposes the current context. if ret.instance_of? Class @klass_cache ||= {} unless @klass_cache[name] proc1 = proc { @context } @klass_cache[name] = Class.new(ret) do @context = proc1.call def self.context @context end end end @klass_cache[name] else ret end else yield end rescue NameError => e yield end end |