Class: Noaidi::Fun
- Inherits:
-
Object
show all
- Defined in:
- lib/noaidi/fun.rb
Instance Method Summary
collapse
Constructor Details
#initialize(noaidi, name, args, block) ⇒ Fun
Returns a new instance of Fun.
5
6
7
8
9
10
|
# File 'lib/noaidi/fun.rb', line 5
def initialize(noaidi, name, args, block)
@module = noaidi
@name = name
@args = args.map{|a| Matcher.new(a)}
@block = block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
25
26
27
|
# File 'lib/noaidi/fun.rb', line 25
def method_missing(name, *args)
@module.public_send(name, *args)
end
|
Instance Method Details
#call(*args) ⇒ Object
12
13
14
15
|
# File 'lib/noaidi/fun.rb', line 12
def call(*args)
freeze unless frozen?
instance_exec(*args, &@block)
end
|
#matches?(args) ⇒ Boolean
17
18
19
20
21
22
23
|
# File 'lib/noaidi/fun.rb', line 17
def matches?(args)
return false unless arity == args.length
args.each_with_index do |arg, i|
return false unless @args[i].match?(arg)
end
true
end
|