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



613
614
615
616
617
618
619
620
621
622
623
# File 'lib/tins/dslkit.rb', line 613

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.



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

def dynamic_scope_name
  @dynamic_scope_name
end

Instance Method Details

#dynamic_defined?(id) ⇒ Boolean

Returns:

  • (Boolean)


602
603
604
605
606
# File 'lib/tins/dslkit.rb', line 602

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



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

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