Ruby Methods: return an usage string when insufficient arguments are given
- by Shyam
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!