Ruby Methods: return an usage string when insufficient arguments are given
Posted
by Shyam
on Stack Overflow
See other posts from Stack Overflow
or by Shyam
Published on 2010-04-14T14:50:41Z
Indexed on
2010/04/14
14:53 UTC
Read the original article
Hit count: 187
Hi,
After creating a serious bunch of classes, with initialize methods, loading them in IRb requires to look back at the code. However, I think it should be easy enough to return a usage message, instead of:
ArgumentError: wrong number of arguments (0 for 9)
So I prefer to return a string with the human readable arguments, by example using "puts" or just a return of a string. Now I have seen the rescue keyword inside begin-end code, but I wonder how I could catch the ArgumentError when the initialize method is called.
Thank you for your answers, feedback and comments!
© Stack Overflow or respective owner