why do I need the @ for setting variable value

Posted by Saad on Stack Overflow See other posts from Stack Overflow or by Saad
Published on 2012-10-05T09:28:45Z Indexed on 2012/10/05 9:37 UTC
Read the original article Hit count: 244

Filed under:

I'm a little confused about scope of variables, in ruby I wrote a test program:

class Test 
        attr_reader :tester 
        def initialize(data) 
                @tester = data 
        end 

        def getData 
                 tester 
        end
end 

puts Test.new(11).getData

now this works fine, the attr_reader, but my confusion is that since I've define attr_reader :tester then why can't I go tester = data rather then @tester = data, because when retrieving the data in getData I only have to write tester and not @tester

© Stack Overflow or respective owner

Related posts about ruby