Sha256: c687c8cebf9aa0515772c7be3ccfce52a05978079abf04ea155548424906d81d

Contents?: true

Size: 491 Bytes

Versions: 3

Compression:

Stored size: 491 Bytes

Contents

# frozen_string_literal: true

require 'ostruct'

module DevRuby
  module Objects
    class BaseObject < OpenStruct
      def initialize(attributes)
        super to_ostruct(attributes)
      end

      def to_ostruct(obj)
        case obj
        when Hash
          OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
        when Array
          obj.map { |o| to_ostruct(o) }
        else # Assumed to be a primitive value
          obj
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dev_ruby-1.0.0 lib/dev_ruby/objects/base_object.rb
dev_ruby-0.2.0 lib/dev_ruby/objects/base_object.rb
dev_ruby-0.1.2 lib/dev_ruby/objects/base_object.rb