(Sorry if this ends as a double post, as I send this using email, but for
some reason it doesn't show in the group. So I am posting it again directly
on the group page.)
Hi All
I'm building a gem and trying to decide what is the best way to provide
return values.
Let's say that my gem add the do_something method to user:
user.do_something
But if that something is already done I want to provide meaningful
feedback, I can't decide what is a best practice here or what is better,
these is what I can think of:
Option 1. return false
res = user .do_something
res //=> false
user.errors //=> ['already done'] information about the errors, like
active record
Option 2. raise an exception (seems a little drastic)
begin
res = user .do_something
rescue MyGem::AlreadyDoneException => e
end
Option 3. return an error code
res = user.do_something
res //=> 3 (meaning already done)
Option 4. return an object
res = user.do_something
res.success //=> false
res.messages //=> ['already done']
Any recommendations on what is a best practice here?
Thanks,
Sebastian
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rails-oceania?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.