Class: Object
- Inherits:
-
BasicObject
- Defined in:
- lib/homeschool.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/homeschool.rb', line 47
def method_missing(method, *args, &block)
match = self.class.pattern_methods.detect do |(pattern, block)|
method.to_s =~ pattern
end
raise super unless match
match[1].bind(self).call(*([$~] + args), &block)
end
|
Class Method Details
.pattern_methods ⇒ Object
39
40
41
|
# File 'lib/homeschool.rb', line 39
def self.pattern_methods
@pattern_methods ||= (superclass && superclass.pattern_methods && superclass.pattern_methods.dup) || []
end
|
.rdef(pattern, &block) ⇒ Object
43
44
45
|
# File 'lib/homeschool.rb', line 43
def self.rdef(pattern, &block)
pattern_methods << [/^#{pattern.source}$/, block]
end
|
Instance Method Details
#dom_id(*suffixes) ⇒ Object
34
35
36
37
|
# File 'lib/homeschool.rb', line 34
def dom_id(*suffixes)
name = suffixes.empty? ? 'element' : suffixes.collect(&:to_s).join('_')
dom_ids[name] = [self.class.name.underscore, self.id, *suffixes].compact.join('_')
end
|
31
32
33
|
# File 'lib/homeschool.rb', line 31
def dom_ids
@dom_ids ||= Hash.new
end
|
#iv_cache(method) ⇒ Object
25
26
27
28
29
|
# File 'lib/homeschool.rb', line 25
def iv_cache(method)
method = method.to_sym.iv
instance_variable_set(method, yield) unless instance_variable_get(method)
instance_variable_get(method)
end
|