Class: AliyunSDK::Common::Struct::Base

Inherits:
Object
  • Object
show all
Extended by:
AttrHelper
Defined in:
lib/aliyun_sdk/common/struct.rb

Defined Under Namespace

Modules: AttrHelper

Instance Method Summary collapse

Methods included from AttrHelper

attrs

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aliyun_sdk/common/struct.rb', line 34

def initialize(opts = {})
  extra_keys = opts.keys - attrs
  unless extra_keys.empty?
    fail Common::Exception,
         "Unexpected extra keys: #{extra_keys.join(', ')}"
  end

  attrs.each do |attr|
    instance_variable_set("@#{attr}", opts[attr])
  end
end

Instance Method Details

#to_sObject



46
47
48
49
50
51
# File 'lib/aliyun_sdk/common/struct.rb', line 46

def to_s
  attrs.map do |attr|
    v = instance_variable_get("@#{attr}")
    "#{attr.to_s}: #{v}"
  end.join(", ")
end