Class: DTO
- Inherits:
-
Struct
- Object
- Struct
- DTO
- Defined in:
- lib/dto.rb
Overview
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ DTO
constructor
A new instance of DTO.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ DTO
Returns a new instance of DTO.
16 17 18 19 20 |
# File 'lib/dto.rb', line 16 def initialize(attrs = {}) members.each do |member| send("#{member}=", attrs[member]) end end |
Instance Method Details
#to_json ⇒ Object
22 23 24 25 26 |
# File 'lib/dto.rb', line 22 def to_json attrs = {} members.each { |attr| attrs[attr] = send(attr) } attrs.to_json end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/dto.rb', line 28 def to_s members.map { |attr| "#{attr}: #{send(attr)}" }.join(", ") end |