Sha256: 20f8ffc5d0cdae3e5116632543e3aa3174e092317cd3762b0d22bc32189820e0

Contents?: true

Size: 510 Bytes

Versions: 4

Compression:

Stored size: 510 Bytes

Contents

# frozen_string_literal: true

require 'ostruct'

module Mpesa
  class Object
    attr_reader :attributes

    def initialize(attributes)
      @attributes = OpenStruct.new(attributes)
    end

    def method_missing(method, *args, &block)
      attribute = @attributes.send(method, *args, &block)
      attribute.is_a?(Hash) ? Object.new(attribute) : attribute
    end

    def respond_to_missing?(_method, _include_private = false)
      true
    end

    def to_hash
      attributes.to_h
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mpesarb-0.3.5 lib/mpesa/object.rb
mpesarb-0.3.4 lib/mpesa/object.rb
mpesarb-0.3.3 lib/mpesa/object.rb
mpesarb-0.3.2 lib/mpesa/object.rb