Sha256: 1404560af93fe438282abdfa6ae75196695f2855c98472443bca65a06034513a
Contents?: true
Size: 408 Bytes
Versions: 10
Compression:
Stored size: 408 Bytes
Contents
# Creates dynamic struct based on arguments class CleanHash STRUCTS = {} def self.create_struct hash raise ArgumentError.new('Not a hash') unless hash.is_a?(Hash) name = 'DynStruct_' + hash.keys.join('_') STRUCTS[name] ||= ::Struct.new(name, *hash.keys.sort) STRUCTS[name].new.tap do |o| hash.each do |k, v| o.send('%s=' % k, v) unless v.nil? end end end end
Version data entries
10 entries across 10 versions & 1 rubygems