Class: ZMQ::Device::Builder
- Inherits:
-
Object
- Object
- ZMQ::Device::Builder
- Defined in:
- lib/zdevice.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(conf = {}) ⇒ Builder
constructor
A new instance of Builder.
- #symbolize_keys(conf) ⇒ Object
Constructor Details
#initialize(conf = {}) ⇒ Builder
Returns a new instance of Builder.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zdevice.rb', line 7 def initialize(conf = {}) conf = symbolize_keys(conf) @context = Context.new(conf.delete(:context)) @devices = {} conf.each do |name, c| @devices[name] = Device.new(name, @context.ctx, c) (class << self; self; end).class_eval do define_method "#{name}" do @devices[name] end end end end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/zdevice.rb', line 34 def close @devices.values.map { |d| d.close } end |
#symbolize_keys(conf) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/zdevice.rb', line 23 def symbolize_keys(conf) recursive = Proc.new do |h, sh| h.each do |k,v| sh[k.to_sym] = v.is_a?(Hash) ? recursive.call(v, {}) : v end sh end recursive.call(conf, {}) end |