Class: Module
Instance Method Summary collapse
- #class_descendants ⇒ Object
- #cmemoize(n, *m) ⇒ Object
- #descendants ⇒ Object
- #memoize(n, *arr) ⇒ Object
Instance Method Details
#class_descendants ⇒ Object
6 7 8 |
# File 'lib/omega/descendants.rb', line 6 def class_descendants ObjectSpace.each_object(Class).select {|c| c < self} end |
#cmemoize(n, *m) ⇒ Object
20 21 22 23 |
# File 'lib/omega/memoize.rb', line 20 def cmemoize n, *m = (class << self; self; end) .memoize n, *m end |
#descendants ⇒ Object
2 3 4 |
# File 'lib/omega/descendants.rb', line 2 def descendants ObjectSpace.each_object(Module).select {|m| m < self} end |
#memoize(n, *arr) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/omega/memoize.rb', line 2 def memoize n, *arr = (class << self; self; end) ([n] + arr).each do |m| meth = instance_method(m) hash = Hash.new define_method m do |*args| if hash.include? args hash[args] else meth = meth.bind(self) if meth.is_a? UnboundMethod v = hash[args] = meth.call(*args) v.freeze v end end end end |