Module: Tins::DynamicScope

Includes:
Scope
Defined in:
lib/tins/dslkit.rb

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scope

#scope, #scope_block, #scope_get, #scope_pop, #scope_push, #scope_reverse, #scope_top

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



623
624
625
626
627
628
629
630
631
632
633
# File 'lib/tins/dslkit.rb', line 623

def method_missing(id, *args)
  self.dynamic_scope_name ||= :variables
  if args.empty? and scope_reverse(dynamic_scope_name) { |c| c.key?(id) and return c[id] }
    super
  elsif args.size == 1 and id.to_s =~ /(.*?)=\Z/
    c = scope_top(dynamic_scope_name) or super
    c[$1] = args.first
  else
    super
  end
end

Instance Attribute Details

#dynamic_scope_nameObject

Returns the value of attribute dynamic_scope_name.



610
611
612
# File 'lib/tins/dslkit.rb', line 610

def dynamic_scope_name
  @dynamic_scope_name
end

Instance Method Details

#dynamic_defined?(id) ⇒ Boolean

Returns:

  • (Boolean)


612
613
614
615
616
# File 'lib/tins/dslkit.rb', line 612

def dynamic_defined?(id)
  self.dynamic_scope_name ||= :variables
  scope_reverse(dynamic_scope_name) { |c| c.key?(id) and return true }
  false
end

#dynamic_scope(&block) ⇒ Object



618
619
620
621
# File 'lib/tins/dslkit.rb', line 618

def dynamic_scope(&block)
  self.dynamic_scope_name ||= :variables
  scope_block(Context.new, dynamic_scope_name, &block)
end