From: Dave Aronson Date: 2012-08-18T03:13:19+09:00 Subject: Re: Default parameters? + (Noob) Guidance On Fri, Aug 17, 2012 at 12:57 PM, incag neato wrote: > How do I write a default value, to account for when the object is called > with no parameter?? I feel I've tried everything: googling/ testing, > re-reading > rubymonk/ testing, rereading ruby doc/ testing; can't get it! Perhaps your Google-fu needs some strengthening. What search string did you use? Googling "ruby default method (parameters OR arguments)" (sans quotes) ought to get you some good hits. But to save you all that, there are a couple ways. The easy way, when it's just a few optional args, is to use = and a value. (Note that all optional args have to be at the end, and you can't skip some and supply later ones.) In your case it would be something like: def say_hello(name = "Qui-Gon Jinn") There is a more complicated way, that will soak up an unlimited number of additional args, but that's for another time. :-) > 2) in moving forward, how would you recommend I teach myself? > a. Michael Hartl's tutorials? or perhaps > b. Chris Pine's PragProg book: "Learn to Program"? Both are excellent. It depends whether you're trying to learn programming (Pine), the Ruby language (Pine), or the Ruby on Rails web app framework (Hartl). If you're already familiar with programming in other languages, you MIGHT do OK starting with Hartl and then referring to sections in Pine (or any other Ruby resources) as needed. -Dave