From: jim o Date: 2007-05-19T07:03:45+09:00 Subject: Re: Beginner question --0-613434214-1179525688=:99674 Content-Type: text/plain; charset=ascii Thank you everyone for all the replies. I think I understand that now. Coming to Ruby from Perl, bare variables have been a point of confusion for me. Heck, I started out just messing with existing scripts, and until I started looking at real documentation I had just assumed that all variables were shown as variables by the #{} notation. This was a big help. As I said, Google was hard with this one as I had no context and my search terms were too vague. Thanks! Jim ----- Original Message ---- From: Avida Networks To: ruby-talk ML Sent: Friday, May 18, 2007 10:25:24 AM Subject: Re: Beginner question hello Guys, let me give another example. let say you want to create a greeting base on a person name. You will write: def greetings(name) "Good Morning #{name.capitalize}" end puts greetings('loi') "Good Morning Loi" as you can see the #{} allows you to create complex expressions. In this case you were able to capitilize the name Loi even though you entered it in lower case letter. So when the interpreter does the interpolation sees the method capitalize and capitalize the name for you. I hope this example will help you Carlos Henriquez On 5/18/07, Sebastian Hungerecker wrote: > > jim o wrote: > > What does the "#{ }" do for you? I think what I am missing is the > feature > > provided by having that as a wrapper vs bare. > > You can't use bare variables inside a string. > x=7 > puts "The number is x" > > This will return (of course) print out "The number is x" because ruby has > no way of knowing that you actually wanted it to print out the value of > the variable x instead of a literal x. If you however put #{} around the > x, > it will be substituted with the value of x. > That's the point of the #{}. There's however no point to pass a string to > puts > that only contains a #{} because than you could as well just pass the > variable > to puts. > > > -- > Ist so, weil ist so > Bleibt so, weil war so > > ____________________________________________________________________________________Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase. http://farechase.yahoo.com/ --0-613434214-1179525688=:99674--