Module: VCSToolkit::Serializable
- Included in:
- Objects::Object
- Defined in:
- lib/vcs_toolkit/serializable.rb
Instance Method Summary collapse
Instance Method Details
#from_hash(hash, **other_args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vcs_toolkit/serializable.rb', line 11 def from_hash(hash, **other_args) kwargs = {} hash.each do |key, value| kwargs[key.to_sym] = value end kwargs.merge! other_args new **kwargs end |
#serialize_on(*attributes) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/vcs_toolkit/serializable.rb', line 3 def serialize_on(*attributes) define_method :to_hash do attribute_values = attributes.map { |attribute| public_send attribute } Hash[attributes.zip(attribute_values)] end end |