Class: Slack::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/laziness/observer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic = nil, observer = nil, func = :update, &blk) ⇒ Observer

Returns a new instance of Observer.



6
7
8
9
10
11
# File 'lib/laziness/observer.rb', line 6

def initialize(topic=nil, observer=nil, func=:update, &blk)
  @topic = topic
  @observer = observer
  @func = func
  @blk = blk
end

Instance Attribute Details

#blkObject (readonly)

Returns the value of attribute blk.



4
5
6
# File 'lib/laziness/observer.rb', line 4

def blk
  @blk
end

#funcObject (readonly)

Returns the value of attribute func.



4
5
6
# File 'lib/laziness/observer.rb', line 4

def func
  @func
end

#observerObject (readonly)

Returns the value of attribute observer.



4
5
6
# File 'lib/laziness/observer.rb', line 4

def observer
  @observer
end

#topicObject

Returns the value of attribute topic.



3
4
5
# File 'lib/laziness/observer.rb', line 3

def topic
  @topic
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
22
# File 'lib/laziness/observer.rb', line 18

def ==(other)
  return false if other.nil?
  self.topic == other.topic && self.blk == other.blk &&
    self.observer == other.observer && self.func == other.func
end

#execute(*args) ⇒ Object



13
14
15
16
# File 'lib/laziness/observer.rb', line 13

def execute(*args)
  blk.call(*args) if blk
  observer.send func, *args if observer && observer.respond_to?(func)
end