Sha256: 2da73d95a3e7feb5c13eac4eb8875072b75e1b5be45425bd62cf00e83240a8d9
Contents?: true
Size: 600 Bytes
Versions: 55
Compression:
Stored size: 600 Bytes
Contents
# DTO class allows to create a structure that support # export to json and construct with a hash. # # Example of use: # # class User < DTO.new(:first_name, :last_name, :birthday) # # end # # or # # User = Class.new(DTO.new :first_name, :last_name, :birthday) # class DTO < Struct def initialize(attrs = {}) members.each do |member| send("#{member}=", attrs[member]) end end def to_json attrs = {} members.each { |attr| attrs[attr] = send(attr) } attrs.to_json end def to_s members.map { |attr| "#{attr}: #{send(attr)}" }.join(", ") end end
Version data entries
55 entries across 55 versions & 1 rubygems