lib/lite/ruby/open_struct.rb in lite-ruby-1.0.24 vs lib/lite/ruby/open_struct.rb in lite-ruby-1.0.25
- old
+ new
@@ -31,14 +31,28 @@
key = key.to_sym unless key.is_a?(Symbol)
@table[key] = val
end
def attributes
- each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
+ @table
end
def replace(args)
args.each_pair { |key, val| send("#{key}=", val) }
end
+
+ def to_hash(table: true)
+ return attributes unless table
+
+ { table: attributes }
+ end
+
+ alias to_h to_hash
+
+ def to_json(table: true)
+ to_hash(table: table).to_json
+ end
+
+ alias as_json to_json
end
end