Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Benjamin Raskin
Benjamin Raskin
4,075 Points

@user vs User vs user explained?

Amateur coder here. Can someone please help explain the difference between these and when you use each?

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

@user is an instance variable and for if you want to use the variable anywhere in your program, user is a local variable and works only in the method it was written in, User would be the name of a class you create. Hope this helps!

P.S. If any of this does not make sense it will be explained in later ruby courses.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

@user - instance variable

user - local variable

User - name of the whole class

To understand the first two, you have to learn about variable scope. To understand classes, you have to know how object-oriented programming works.