Class: SimpleStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/bottlerocket/simple_struct.rb

Direct Known Subclasses

ContentType, Entity

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ SimpleStruct

Returns a new instance of SimpleStruct.



4
5
6
# File 'lib/bottlerocket/simple_struct.rb', line 4

def initialize(attributes={})
  self.attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(field, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bottlerocket/simple_struct.rb', line 12

def method_missing(field, *args)
  begin
    if field.to_s.end_with?('=')
      field_name = field.to_s.sub '=', ''
      @attributes[field_name] = args.first
    else
      @attributes[field]
    end
  rescue
    super(field, *args)
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



2
3
4
# File 'lib/bottlerocket/simple_struct.rb', line 2

def attributes
  @attributes
end