Class: Aliyun::Log::Common::AttrStruct
- Inherits:
-
Object
- Object
- Aliyun::Log::Common::AttrStruct
- Extended by:
- AttrHelper
- Defined in:
- lib/aliyun/log/common/attr_struct.rb
Direct Known Subclasses
Defined Under Namespace
Modules: AttrHelper
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ AttrStruct
constructor
A new instance of AttrStruct.
- #to_s ⇒ Object
Methods included from AttrHelper
Constructor Details
#initialize(opts = {}) ⇒ AttrStruct
Returns a new instance of AttrStruct.
16 17 18 19 20 21 22 23 |
# File 'lib/aliyun/log/common/attr_struct.rb', line 16 def initialize(opts = {}) extra_keys = opts.keys - attrs raise "Unexpected extra keys: #{extra_keys.join(', ')}" unless extra_keys.empty? attrs.each do |attr| instance_variable_set("@#{attr}", opts[attr]) end end |
Instance Method Details
#to_s ⇒ Object
25 26 27 28 29 30 |
# File 'lib/aliyun/log/common/attr_struct.rb', line 25 def to_s attrs.map do |attr| v = instance_variable_get("@#{attr}") "#{attr}: #{v}" end.join(', ') end |