lib/storazzo/hashify.rb in storazzo-0.5.7 vs lib/storazzo/hashify.rb in storazzo-0.6.1
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
# copied from https://dev.to/ayushn21/how-to-generate-yaml-from-ruby-objects-without-type-annotations-4fli
module Storazzo
module Hashify
# Classes that include this module can exclude certain
# instance variable from its hash representation by overriding
@@ -18,22 +20,22 @@
next if excluded_ivars.include? var.to_s
value = instance_variable_get(var)
value = value.map(&:to_hash) if value.is_a? Array
- hash[var.to_s.delete("@")] = value
+ hash[var.to_s.delete('@')] = value
end
- return hash
+ hash
end
def obj_to_hash
h = {}
puts self
- self.instance_variables.each { |var|
+ instance_variables.each do |var|
# puts var
- h[var.to_s.delete('@')] = self.instance_variable_get(var) # send(var.to_s.delete('@'))
- }
+ h[var.to_s.delete('@')] = instance_variable_get(var) # send(var.to_s.delete('@'))
+ end
h
end
def to_yaml
to_hash.to_yaml