From: Robert Klemme Date: 2012-08-18T02:11:06+09:00 Subject: Re: Default parameters? + (Noob) Guidance On Fri, Aug 17, 2012 at 6:57 PM, incag neato wrote: > Hi guys, would love your help with a few questions: Welcome to the wonderful world of Ruby! > 1) working on the RubyMonk.com primer. > It's pretty good, but it got vague and super challenging all of a > sudden. (or maybe i just got dumb.) > > This is where I am stumped: > > def say_hello(name) > "Hello, #{name}." > end > > The output: > > returns "Hello, Master." when say_hello("Master") is called ✔ > Error: returns "Hello, Qui-Gon Jinn." > when say_hello is called with no parameters > Error: wrong number of arguments (0 for 1) > > The question: > > 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 Maybe it's because your terminology is wrong in one place: you call (or invoke) a method - not an object. say_hello is a method. Default arguments are declared with an assignment like this def say_hello(name = "nobody") "Hello, #{name}." end > 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"? I can't really comment on that - since I used neither to learn Ruby. Chris Pine's book is recommended quite often so maybe that's a good choice. Other than that what I find most helpful is to have real problems or tasks I try to solve / fulfill and then I grab the knowledge I need for the task at hand. The advantage is that the motivation to solve things you really want to get solved is certainly higher as for to tasks in tutorials. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/