Serialize methods by to_json

Hello,

Is there possible to pass arguments for serialized methods using
to_json??
I want to serialize my collection of users with income and outcome which
is calculate by methods:

collection.to_json(:methods => [:income, :outcome])

But, what if I need to pass some arguments to method :outcome ?

Thanks

I don’t believe you can pass params using the methods option. One
approach would be to calculate the outcome on the collection before
calling to_json.

def calculate_outcome(arg)
@outcome = # do calculation with arg
end

def outcome
@outcome
end

collection.each {|c| c.calculate_outcome(arg)}
collection.to_json(:methods => [:income, :outcome])

HTH,
Nicholas

On Jun 23, 4:45 am, Gregory P. [email protected]