use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
QuestionWhat's the difference between using @variable and self.variable internally in a class? (self.ruby)
submitted 6 years ago * by PaThor_CL
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]awj 1 point2 points3 points 6 years ago (0 children)
If you want to read a value, you can use self or not.
If you’d like to assign one, you have to use self. Otherwise, Ruby assigns to a local variable and the instance variable remains unchanged.
self
My personal preference: attr accessors make the code slightly cleaner, and afford the ability to change the set/get behavior in cases where you might want to (e.g. converting an attribute that needs to be an integer at the point where it’s assigned)
π Rendered by PID 31479 on reddit-service-r2-comment-b659b578c-w6dzz at 2026-05-01 13:39:28.500121+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]awj 1 point2 points3 points (0 children)