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 6552627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:28:58+00:00 2026-05-25T12:28:58+00:00

In Michael Hartl’s tutorial he has a module SessionsHelper , which has a method

  • 0

In Michael Hartl’s tutorial he has a module SessionsHelper, which has a method called current_user= which accepts a parameter and assigns it to @current_user. He then invokes this in various other methods in his program using a line like current_user = User.first.

My question is how we know that the current_user= method is being called at all — it seems to me that what would actually be happening is a new variable called current_user is created on the spot, given the value of User.first, and then when the function closes that variable dies.

I also tested this simply by creating the following code:

def x= val
puts "method called"
end

x = 46
puts x

This code snippet simply prints 46 on the screen – the function x= is never called at all. So what is the current_user= method doing in Michael Hartl’s tutorial, and how does he cause that function to be called?

  • 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-05-25T12:28:58+00:00Added an answer on May 25, 2026 at 12:28 pm

    It’s because Ruby treat expressions that can be read as simple variable as simple variable. You can see it with this code:

    def x
      10
    end
    
    print x      #=> 10
    x = 5
    print x      #=> 5
    print x()    #=> 10
    print self.x #=> 10
    

    This is the same case. Look:

    def x=(a)
      print a
    end
    
    x = 8      #=> Variable 'x' assigned to 8
    x=(8)      #=> The same
    
    self.x = 8 #=> Function called
    

    Also remember that assignment functions (like the last one) can’t return any value, the return value will always be the last argument.

    def x=(a)
      return a+1
    end
    
    var = (self.x = 8) #=> Function called; Variable 'var' assigned to 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Release It! , Michael Nygard reasons that many catastrophic system failures are often
I recently set up a new account with github. I'm following a Rails tutorial
I have been doing Michael Foord's IronPython&Winforms tutorials in the interactive console. Is it
I saw Michael Sparks's very interesting dissection of Peter Norvig's Spell Checker at the
Inspired after watching Michael Feather's SCNA talk Self-Education and the Craftsman , I am
I just recently finished Michael Feathers' book Working Effectively with Legacy Code . It
Sample Text: SUBJECT = 'NETHERLANDS MUSIC EPA' CONTENT = 'Michael Buble performs in Amsterdam
Michael Feathers, in Working Effectively With Legacy Code , on pages 13-14 mentions: A
I recently read Michael C. Feathers' book Working effectively with legacy code and came
I'm using the mock library written by Michael Foord to help with my testing

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.