Class: FisherClassifier::Config
- Inherits:
-
Object
- Object
- FisherClassifier::Config
show all
- Defined in:
- lib/fisher_classifier/config.rb
Instance Method Summary
collapse
Constructor Details
#initialize(block) ⇒ Config
Returns a new instance of Config.
4
5
6
7
8
9
10
11
12
|
# File 'lib/fisher_classifier/config.rb', line 4
def initialize(block)
@config = {
fisher_threshold: 0,
weight: 1.0,
assumed_prob: 0.5
}
@methods = {}
instance_eval &block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, value = nil, &block) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/fisher_classifier/config.rb', line 26
def method_missing(key, value = nil, &block)
if block_given?
@methods[key] = block
else
@config[key] = value
end
end
|
Instance Method Details
#call(name, *args) ⇒ Object
20
21
22
23
24
|
# File 'lib/fisher_classifier/config.rb', line 20
def call(name, *args)
raise "'#{name}' mehtod does not defined in config" unless @methods.has_key? name
@methods[name].call *args
end
|
#get(key) ⇒ Object
14
15
16
17
18
|
# File 'lib/fisher_classifier/config.rb', line 14
def get(key)
raise "'#{key}' value does not defined in config" unless @config.has_key? key
@config[key]
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
34
35
36
|
# File 'lib/fisher_classifier/config.rb', line 34
def respond_to_missing?(method_name, include_private = false)
@methods.has_key? method_name
end
|