Module: BinaryParser::Memorize::Extension
- Defined in:
- lib/binary_parser/general_class/memorize.rb
Instance Attribute Summary collapse
-
#memorize_methods ⇒ Object
Returns the value of attribute memorize_methods.
Instance Method Summary collapse
Instance Attribute Details
#memorize_methods ⇒ Object
Returns the value of attribute memorize_methods.
5 6 7 |
# File 'lib/binary_parser/general_class/memorize.rb', line 5 def memorize_methods @memorize_methods end |
Instance Method Details
#memorize(method_name) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/binary_parser/general_class/memorize.rb', line 15 def memorize(method_name) pure_method_name = "pure_#{method_name}".to_sym alias_method pure_method_name, method_name define_method(method_name) do |arg| @memo ||= Hash.new @memo[method_name] ||= Hash.new @memo[method_name][arg] ||= send(pure_method_name, arg) end end |
#method_added(method_name) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/binary_parser/general_class/memorize.rb', line 7 def method_added(method_name) @memorized ||= Hash.new if @memorize_methods.include?(method_name) && !@memorized[method_name] @memorized[method_name] = true memorize(method_name) end end |