From: Ammar Ali Date: 2010-07-13T06:23:42+09:00 Subject: Re: Substitution --001636c928a6d5b1f5048b375dc9 Content-Type: text/plain; charset=UTF-8 On Mon, Jul 12, 2010 at 11:30 PM, Abder-rahman Ali < abder.rahman.ali@gmail.com> wrote: > > Maybe your solution is a thing I was thinking of. > It not a solution really, just the basic syntax. But, can you kindly tell me how the gsub! method is working on the > example? The gsub! does not replace values in the hash, it is operating on the string that is returned by gets. Consider the following: str = "Some short string" puts str # prints "Some short string" str.gsub!('short', 'small') puts str # prints "Some small string" Adding some print statements can help you see what is going on. Try running the following: info = { 'Name' => 'Joe', 'Age' => '20' } template = "Name is Age years old" puts "template = #{template}" info.each do |key, value| puts "replacing #{key} with #{value}" template.gsub!(key, value) puts "template = #{template}" end Hope that helps, Ammar --001636c928a6d5b1f5048b375dc9--