Class: SimpleResponse::SimpleStruct

Inherits:
Object
  • Object
show all
Includes:
QueryMethods
Defined in:
lib/simple_response/simple_struct.rb

Overview

SimpleStruct class is an OpenStruct-like class that allows to assign and read arbitrary values.

Direct Known Subclasses

Response

Instance Method Summary collapse

Methods included from QueryMethods

#existing_query_method?

Constructor Details

#initialize(**args) ⇒ SimpleStruct

Returns a new instance of SimpleStruct.



7
8
9
# File 'lib/simple_response/simple_struct.rb', line 7

def initialize(**args)
  @attributes = args.dup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simple_response/simple_struct.rb', line 17

def method_missing(name, *args, &block)
  if existing_query_method?(name)
    query_method(name)
  elsif write_method?(name)
    @attributes[name[0...-1].to_sym] = args.first
  elsif existing_attribute?(name)
    @attributes[name.to_sym]
  else
    super
  end
end

Instance Method Details

#keysObject



11
12
13
# File 'lib/simple_response/simple_struct.rb', line 11

def keys
  @attributes.keys
end