Class: Protobuf::Rpc::Env
- Inherits:
-
Hash
- Object
- Hash
- Protobuf::Rpc::Env
- Defined in:
- lib/protobuf/rpc/env.rb
Class Method Summary collapse
-
.hash_accessor(*names) ⇒ Object
Creates an accessor that simply sets and reads a key in the hash:.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Env
constructor
A new instance of Env.
Constructor Details
#initialize(options = {}) ⇒ Env
Returns a new instance of Env.
51 52 53 54 55 |
# File 'lib/protobuf/rpc/env.rb', line 51 def initialize(={}) merge!() 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| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} self['#{name}'] end def #{name}=(value) self['#{name}'] = value end def #{name}? ! self['#{name}'].nil? end METHOD end end |