Module: Shallow::Method
- Defined in:
- lib/shallow.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.with_cache_clearing_for(context) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/shallow.rb', line 6 def self.with_cache_clearing_for(context) yield and return unless context.respond_to?(:returning_value_cache_caller) old_method = context.method(:returning_value_cache_caller) context.(:returning_value_cache_caller) do Shallow::Caller::Clear end yield ensure context.(:returning_value_cache_caller, &old_method) end |
Instance Method Details
#shallow_method(method_name, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shallow.rb', line 17 def shallow_method(method_name, = {}) scope = [:scope] || ['scope'] || lambda { nil } class_eval do define_method(:returning_value_cache_caller) do Shallow::Caller::Base end old_method = instance_method(method_name.to_sym) define_method(method_name.to_sym) do |*args, &block| returning_value_cache_caller.new( :args => args, :keys => [instance_eval(&scope).to_s, method_name], :capture => old_method.bind(self) ).call(&block) end end end |