Class: Benchmark::Sweet::Item
- Inherits:
-
Object
- Object
- Benchmark::Sweet::Item
- Defined in:
- lib/benchmark/sweet/item.rb
Overview
borrowed heavily from Benchmark::IPS::Job::Entry may be able to fallback on that - will need to generate a &block friendly proc for that structure
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #block ⇒ Object
-
#compile(str) ⇒ Object
to use with Job::Entry…
-
#initialize(label, action = nil) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(label, action = nil) ⇒ Item
Returns a new instance of Item.
7 8 9 10 |
# File 'lib/benchmark/sweet/item.rb', line 7 def initialize(label, action = nil) @label = label @action = action || @label[:method] #raise("Item needs an action") end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/benchmark/sweet/item.rb', line 6 def action @action end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/benchmark/sweet/item.rb', line 6 def label @label end |
Instance Method Details
#block ⇒ Object
12 13 14 |
# File 'lib/benchmark/sweet/item.rb', line 12 def block @block ||= action.kind_of?(String) ? compile(action) : action end |
#compile(str) ⇒ Object
to use with Job::Entry… def call_once ; call_times(1) ; end def callback_proc
lambda(&method(:call_once))
end
21 22 23 24 25 26 27 |
# File 'lib/benchmark/sweet/item.rb', line 21 def compile(str) eval <<-CODE Proc.new do #{str} end CODE end |