Class: Protobuf::Rpc::Env

Inherits:
Hash
  • Object
show all
Defined in:
lib/protobuf/rpc/env.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Env

Returns a new instance of Env.



53
54
55
56
57
# File 'lib/protobuf/rpc/env.rb', line 53

def initialize(options = {})
  merge!(options)

  self['worker_id'] = ::Thread.current.object_id.to_s(16)
end

Class Method Details

.hash_accessor(*names) ⇒ Object

Creates an accessor that simply sets and reads a key in the hash:

class Config < Hash hash_accessor :app end

config = Config.new config.app = Foo config[:app] #=> Foo

config[:app] = Bar config.app #=> Bar



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/protobuf/rpc/env.rb', line 17

def self.hash_accessor(*names) #:nodoc:
  names.each do |name|
    name_str = name.to_s.freeze

    define_method name do
      self[name_str]
    end

    define_method "#{name}=" do |value|
      self[name_str] = value
    end

    define_method "#{name}?" do
      !self[name_str].nil?
    end
  end
end