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



603
604
605
606
607
608
609
610
611
612
613
# File 'lib/tins/dslkit.rb', line 603

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.



590
591
592
# File 'lib/tins/dslkit.rb', line 590

def dynamic_scope_name
  @dynamic_scope_name
end

Instance Method Details

#dynamic_defined?(id) ⇒ Boolean

Returns:

  • (Boolean)


592
593
594
595
596
# File 'lib/tins/dslkit.rb', line 592

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



598
599
600
601
# File 'lib/tins/dslkit.rb', line 598

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