Module: SimpleTimeMeasure::ClassMethods
- Defined in:
- lib/simple_time_measure.rb
Instance Method Summary collapse
Instance Method Details
#measure_class_method(name) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/simple_time_measure.rb', line 53 def measure_class_method(name) m = Module.new do define_method name do |*args| result = nil time = SimpleTimeMeasure.time do result = super(*args) end yield(time) if block_given? result end end SimpleTimeMeasure.base_singleton_class.prepend m end |
#measure_instance_method(name) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/simple_time_measure.rb', line 38 def measure_instance_method(name) m = Module.new do define_method name do |*args| result = nil time = SimpleTimeMeasure.time do result = super(*args) end yield(time) if block_given? result end end prepend m end |