Class: VER::Action
- Inherits:
-
Struct
- Object
- Struct
- VER::Action
- Defined in:
- lib/ver/action.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#block ⇒ Object
Returns the value of attribute block.
-
#last ⇒ Object
Returns the value of attribute last.
-
#method ⇒ Object
Returns the value of attribute method.
-
#receiver ⇒ Object
Returns the value of attribute receiver.
Instance Method Summary collapse
- #call(widget, *given_args) ⇒ Object
- #combine(action) ⇒ Object
-
#initialize(receiver = nil, method = nil, args = [], &block) ⇒ Action
constructor
A new instance of Action.
- #to_s ⇒ Object
Constructor Details
#initialize(receiver = nil, method = nil, args = [], &block) ⇒ Action
Returns a new instance of Action.
3 4 5 6 7 8 9 |
# File 'lib/ver/action.rb', line 3 def initialize(receiver = nil, method = nil, args = [], &block) self.receiver = receiver self.method = method || :call self.args = args self.block = block self.last = [self.receiver, self.method, self.args] end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args
2 3 4 |
# File 'lib/ver/action.rb', line 2 def args @args end |
#block ⇒ Object
Returns the value of attribute block
2 3 4 |
# File 'lib/ver/action.rb', line 2 def block @block end |
#last ⇒ Object
Returns the value of attribute last
2 3 4 |
# File 'lib/ver/action.rb', line 2 def last @last end |
#method ⇒ Object
Returns the value of attribute method
2 3 4 |
# File 'lib/ver/action.rb', line 2 def method @method end |
#receiver ⇒ Object
Returns the value of attribute receiver
2 3 4 |
# File 'lib/ver/action.rb', line 2 def receiver @receiver end |
Instance Method Details
#call(widget, *given_args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ver/action.rb', line 11 def call(, *given_args) args = [*self.args, *given_args] if receiver = self.receiver self.last = [receiver, method, .tk_pathname, args] receiver.send(method, , *args) elsif receiver = if .respond_to?(:event) self.last = [.tk_pathname, method, .event, args] .send(method, .event, *args) else self.last = [.tk_pathname, method, , args] .send(method, , *args) end end rescue => ex puts self pp ex, ex.backtrace end |
#combine(action) ⇒ Object
31 32 33 34 |
# File 'lib/ver/action.rb', line 31 def combine(action) new_args = [*args, action].compact self.class.new(receiver, method, new_args, &block) end |
#to_s ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ver/action.rb', line 36 def to_s receiver, method, , *args = last joined = [, *args.map{|arg| arg.inspect }].compact.join(' ') "%s.%s(%s)" % [receiver, method, joined] end |