Class: Scoped::ScopeCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/scoped/scope_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ScopeCollection

Returns a new instance of ScopeCollection.



3
4
5
6
# File 'lib/scoped/scope_collection.rb', line 3

def initialize(&block)
  @scopes = {}
  instance_eval &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/scoped/scope_collection.rb', line 12

def method_missing(name, *args, &block)
  return super unless block_given?

  arg_list, block_contents = parse(block.source.split("\n"))

  @scopes[name] = <<-RUBY
    lambda do #{"|#{arg_list}|" if arg_list}
      #{block_contents.join("\n")}
    end
  RUBY
end

Instance Method Details

#allObject



8
9
10
# File 'lib/scoped/scope_collection.rb', line 8

def all
  @scopes
end