From: "Jesús Gabriel y Galán" Date: 2012-12-04T21:00:56+09:00 Subject: Re: What is wrong in this On Tue, Dec 4, 2012 at 12:45 PM, Mallikarjuna Yaddala wrote: > $rr_msg = "hello" > > task :default do > display "rr" > end > > def display(msg) > ss = msg+"_msg" > puts "#{$ss}" > end > > > My aim is to construct a global var ($rr_msg) and get the value ... You can't construct a variable like that. In order to do this you need to use eval: 1.9.2p290 :001 > $rr_msg = "test" => "test" 1.9.2p290 :002 > var = "rr" => "rr" 1.9.2p290 :004 > eval "$#{var}_msg" => "test" But there's another way. Instead of constructing a variable, you could create a hash whose keys are the "variables": $messages = {"rr" => "test"} # not sure it needs to be global, but whatever def display message_id puts $messages[message_id] end display "rr" #=> test Jesus.