Class: Class::MethodHandler
- Inherits:
-
Object
- Object
- Class::MethodHandler
- Defined in:
- lib/define_method_handler.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#second_priority ⇒ Object
readonly
Returns the value of attribute second_priority.
Instance Method Summary collapse
- #condition(&blk) ⇒ Object
- #execute?(chain, *args) ⇒ Boolean
-
#initialize(processor, sprior, group, prior = 0) ⇒ MethodHandler
constructor
A new instance of MethodHandler.
Constructor Details
#initialize(processor, sprior, group, prior = 0) ⇒ MethodHandler
Returns a new instance of MethodHandler.
36 37 38 39 40 41 |
# File 'lib/define_method_handler.rb', line 36 def initialize(processor, sprior, group, prior = 0) @processor = processor @priority = prior @second_priority = sprior @group = group end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
33 34 35 |
# File 'lib/define_method_handler.rb', line 33 def group @group end |
#method_name ⇒ Object
Returns the value of attribute method_name.
34 35 36 |
# File 'lib/define_method_handler.rb', line 34 def method_name @method_name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
31 32 33 |
# File 'lib/define_method_handler.rb', line 31 def priority @priority end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
30 31 32 |
# File 'lib/define_method_handler.rb', line 30 def processor @processor end |
#second_priority ⇒ Object (readonly)
Returns the value of attribute second_priority.
32 33 34 |
# File 'lib/define_method_handler.rb', line 32 def second_priority @second_priority end |
Instance Method Details
#condition(&blk) ⇒ Object
65 66 67 68 |
# File 'lib/define_method_handler.rb', line 65 def condition(&blk) @condition = blk self end |
#execute?(chain, *args) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/define_method_handler.rb', line 43 def execute?(chain, *args) if @condition tmp_method = "tmpmethod#{rand(1000000)}#{Time.now.to_i}" begin local_condition = @condition chain.class.class_eval do define_method(tmp_method, &local_condition) end chain.send(tmp_method,*args) ensure begin chain.class.class_eval do remove_method(tmp_method) end rescue NameError end end else true end end |