On 12/10/2012, at 9:33 AM, Muhammad Salman <lists / ruby-forum.com> wrote:

> I am relatively new to Ruby. In the below code which redefines the
> attr_accessor method i cannot understand the #{attr} and @#{attr}. I
> know # as comment and @ as required for a instance variable in Ruby.


%Q{
     def #{attr}
       @#{attr}
     end
     def #{attr}=(value)
       @#{attr} = value
     end
     }



The # symbol when used with {} is for string interpolation, e.g..

f = "world"
puts "hello #{f}"


%Q is another way of defining a string with interpolation, e.g.

f = %Q{world}
puts "hello #{f}"



Henry