Need explanation for this

hi please gice explanation for this

1: def json_attributes_for(model, *attrs)
2: attrs = [attrs].flatten.map(&:to_s)
3: model.attributes.delete_if{|k,v| !attrs.include?(k) }.to_json
4: end

hi please gice explanation for this

1: def json_attributes_for(model, *attrs)
2: attrs = [attrs].flatten.map(&:to_s)
3: model.attributes.delete_if{|k,v| !attrs.include?(k) }.to_json
4: end

It returns a json hash for the object, but only including the
specified attributes. It's rewriting the wheel though, first of hashes
have a slice method so that messing around with delete_if is not
needed, and secondly to_json takes a :only option.

Fred