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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:21:09+00:00 2026-05-28T20:21:09+00:00

I am a NOOB trying to understand some code. What does this self.class.current_section do?

  • 0

I am a NOOB trying to understand some code.

What does this self.class.current_section do?

class MyClass
  class << self  
    def current_section(*section)
      if section.empty?
        @current_section
      else
        @current_section = section[0]
      end
    end
  end


  def current_section()
    self.class.current_section
  end

  def current_section=(section)
    self.class.current_section(section)
  end
end
  • 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-28T20:21:09+00:00Added an answer on May 28, 2026 at 8:21 pm

    It forwards the message (method call request) received by the object to the corresponding class.

    Say you have a class

    class MyClass
      def MyClass.current_section
        puts "I'm the class method."
      end
    
      def current_section
        self.class.current_section
      end
    end
    
    h = MyClass.new
    h.current_section # outputs "I'm the class method."
    

    Calling h‘s method, it looks up h‘s class (MyClass) and invokes the method current_section of that class.

    So, by the definitions above, every object of the class MyClass has a method current_section which is routed to the central current_section of the class.

    The definition of the class methods in your question is just using a different syntax for doing the same: adding a method to the class object.

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

Sidebar

Related Questions

I'm trying to debug some auto-generated code, but I am a mySQL noob. Everything
Being a noob in Iphone dev, just trying to understand. In the code below,
a C++ noob here. I am trying to tweak some code, with the following
noob here still experimenting with templates. Trying to write a message processing class template
This is probably a noob question but I've been trying to figure it out
This is a fairly noob question. I'm trying to set up a dev environment
Complete sql noob here. Trying to think about a way to store some data
I'm a sql noob trying to get this query to use 2 tables. tables
I'm a noob trying to do this: <% if @page[:title] == Portraits %> <%=
so I was watching a tutorial and I am trying to understand this syntax

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.