Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:36:11+00:00 2026-06-12T03:36:11+00:00

When I started learning Ruby, I started with Michael Hartl’s excellent Rails Tutorial .

  • 0

When I started learning Ruby, I started with Michael Hartl’s excellent Rails Tutorial. I just revisited the tutorial and noticed that portions of the example application code were modified. In the authentication chapter two methods were changed:

# SessionsHelper
def sign_in(user)
  ...
  self.current_user = user
end

def sign_out
  self.current_user = nil
  ...
end

Previously, the keyword self was omitted. But the app worked. So, if it ain’t broke, why fix it? What value has self added and why is it used?

I understand that self defines class methods as opposed to instance methods. And in models, using self allows us to reference an object’s property directly. But I can’t tie the dots and see how it’s being used in a helper. I’ve seen it in controllers before and I can’t understand why we would want to use it there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:36:13+00:00Added an answer on June 12, 2026 at 3:36 am

    [Edit]

    It is likely that the original section of the tutorial was just plain wrong. Omitting the “self” receiver causes the methods to assign a value to the method local variable “current_user” with no other effect.

    My original answer below is incorrect and should be ignored (because writer methods foo=(x) cannot be called without a receiver, as can other methods).

    [Incorrect Original Answer Below]

    The reason for using the “self” receiver is likely for clarity.

    If “self” is omitted then, to the untrained eye, it looks like you are simply assigning the “user” variable to a new variable named “current_user” with no other effect. Experienced Rubyists know that if there is a method named “current_user” on the object instance then it will be called instead of just creating and assigning a new variable but this detail can easily be overlooked, especially if the method is inherited or otherwise not declared in the current class definition section.

    By using the “self” keyword explicitly you are clearly stating that you are calling a method on this object instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning Ruby. I typed the example : x = 10 5.times
I have just started learning ruby on rails. I have a doubt wrt routing.
I have just started learning Ruby on Rails. I happened to look for prevention
I've just started learning Ruby on Rails and it's a newbie question. I did
I've only just started learning ruby on rails and I would like to create
I've just started learning Ruby and Ruby on Rails and came across validation code
I just started learning ruby on rails with Lynda Ruby on Rails 3 Essential
I've just started learning Ruby on rails and I am wondering how to do
I have just started out learning rails and ruby, so please bear with me
I am learning ruby on rails with the Getting Started tutorial on the official

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.