如何列出我的应用程序内的所有使用者?

问题描述 投票:0回答:1

现在我声明了类级变量

MyConsumer << Bunny::Consumer
   def initialize( [skip] )
     @@consumers ||= []
     [skip]
     at_exit{ self.unregister_and_close }
     @@consumers << self
     [skip]
   end
end

但是,也许在Bunny lib中有一个消费者列表?到目前为止没有找到任何东西

ruby rabbitmq bunny
1个回答
-1
投票
您应该能够编写遍历使用者的类方法。

MyConsumer << Bunny::Consumer def initialize( * ) @@consumers ||= [] # other operations at_exit{ self.unregister_and_close } @@consumers << self # other operations end def self.list @@consumers ||= [] @@consumers.each do |consumer| puts consumer end end end MyConsumer.new =>#<MyConsumer:0x0000001031CA58> MyConsumer.new =>#<MyConsumer:0x0000000b896510> MyConsumer.new =>#<MyConsumer:0x00000001041a38> MyConsumer.list #<MyConsumer:0x0000001031CA58> #<MyConsumer:0x0000000b896510> #<MyConsumer:0x00000001041a38> => [#<MyConsumer:0x0000001031CA58>, #<MyConsumer:0x0000000b896510>, #<MyConsumer:0x00000001041a38>]

© www.soinside.com 2019 - 2024. All rights reserved.