Class: Telegram::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallback



5
6
7
8
9
# File 'lib/telegram/callback.rb', line 5

def initialize
  @success = nil
  @fail = nil
  @data = nil
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/telegram/callback.rb', line 3

def data
  @data
end

Instance Method Details

#callback(&cb) ⇒ Object



11
12
13
# File 'lib/telegram/callback.rb', line 11

def callback(&cb)
  @success = cb
end

#errback(&cb) ⇒ Object



15
16
17
# File 'lib/telegram/callback.rb', line 15

def errback(&cb)
  @fail = cb
end

#trigger(type = :success, data = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/telegram/callback.rb', line 19

def trigger(type = :success, data = nil)
  @data = data
  case type
  when :success
    @success.call
  when :fail
    @fail.call
  end
end