lib/jsonify/json_value.rb in jsonify-0.0.1 vs lib/jsonify/json_value.rb in jsonify-0.0.2

- old
+ new

@@ -27,17 +27,17 @@ def values @values.values end - def add(val) - raise ArgumentError.new("Cannot add #{val} to JsonOject") unless (Array === val || JsonPair === val) - val = JsonPair.new(val.shift, val.length <= 1 ? val.first : val) if Array === val - @values.store(val.key, val) + def add(key, val=nil) + pair = (JsonPair === key) ? key : JsonPair.new(key, val) + @values.store(pair.key, pair) end alias_method :<<, :add + alias_method :add!, :add # for consistency with the Builder api end class JsonArray < JsonValue @@ -53,9 +53,10 @@ end super(value) end alias_method :<<, :add + alias_method :add!, :add # for consistency with the Builder api end class JsonPair < JsonValue attr_accessor :key, :value \ No newline at end of file