Class: Class

Inherits:
Object show all
Defined in:
lib/strokedb/util/class_optimization.rb

Instance Method Summary collapse

Instance Method Details

#declare_optimized_methods(lang, *meths, &block) ⇒ Object

Declare which methods are optimized for particular language. It is assumed, that optimized method name looks that way: method_name_(language name)

If you supply a block of code, it will be executed in a context of a class each time optimize! is called.

You may add some exception handling where you call optimize!.

Example:

# assume, there're methods find_C and insert_C
declare_optimized_methods(:C, :find, :insert) { require 'bundle' }</tt>


17
18
19
20
21
22
23
24
# File 'lib/strokedb/util/class_optimization.rb', line 17

def declare_optimized_methods(lang, *meths, &block)
  meths.flatten!
  @optimized_methods ||= {}
  @optimized_methods_init ||= {}
  @optimized_methods[lang.to_s] = meths
  @optimized_methods_init[lang.to_s] = block
  extend ClassOptimization::ClassMethods
end

#optimized_methods(lang = nil) ⇒ Object

Returns a list of optimized methods for a given language. If no language given, a Hash is returned where key is a language name.



29
30
31
32
33
# File 'lib/strokedb/util/class_optimization.rb', line 29

def optimized_methods(lang = nil)
  @optimized_methods ||= {}
  return @optimized_methods unless lang 
  @optimized_methods[lang.to_s] || []
end