Class: Require::Dsl
- Inherits:
-
Array
- Object
- Array
- Require::Dsl
show all
- Defined in:
- lib/require/dsl.rb
Defined Under Namespace
Classes: Args
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/require/dsl.rb', line 26
def method_missing(*args, &block)
if args.length == 1 && a = self.get(args[0])
a[1]
else
if block_given?
args << Dsl.new.call(&block)
end
self << Args.new(args)
end
end
|
Instance Method Details
#all(*values) ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/require/dsl.rb', line 4
def all(*values)
if values.empty?
self
else
Dsl.new(self.select { |a| a[0..values.length-1] == values })
end
end
|
#call(&block) ⇒ Object
12
13
14
15
|
# File 'lib/require/dsl.rb', line 12
def call(&block)
instance_eval(&block) if block_given?
self
end
|
#gem(*args, &block) ⇒ Object
21
22
23
24
|
# File 'lib/require/dsl.rb', line 21
def gem(*args, &block)
args.unshift(:gem)
method_missing *args, &block
end
|
#get(*values) ⇒ Object
17
18
19
|
# File 'lib/require/dsl.rb', line 17
def get(*values)
self.detect { |a| a[0..values.length-1] == values }
end
|
#require(*args, &block) ⇒ Object
37
38
39
40
|
# File 'lib/require/dsl.rb', line 37
def require(*args, &block)
args.unshift(:require)
method_missing *args, &block
end
|