Class: InlineTesting::TestEnvironment::Locals

Inherits:
Object
  • Object
show all
Includes:
MetaTools
Defined in:
lib/inline_testing/test_environment/locals.rb,
lib/inline_testing/test_environment/locals.rb

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocals

Returns a new instance of Locals.



36
# File 'lib/inline_testing/test_environment/locals.rb', line 36

def initialize;  @locals = {}; end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



34
35
36
# File 'lib/inline_testing/test_environment/locals.rb', line 34

def locals
  @locals
end

Instance Method Details

#edit(&blk) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/inline_testing/test_environment/locals.rb', line 38

def edit(&blk)
  new_locals = DSL.call(&blk)
  # Check for removed locals.. remove associated methods.. is this ever needed? hmm..
  (@locals.keys - new_locals.keys).each { |local|  metaclass.remove_method(local) }
  @locals = new_locals
  # Add/update methods
  @locals.each do |local, values|
    meta_def(local) { @locals[local][:obj] } unless metaclass.method_defined?(local)
  end
  
  self
end