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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:25:44+00:00 2026-06-01T02:25:44+00:00

If self is the default receiver in ruby and you call ‘puts’ in an

  • 0

If self is the default receiver in ruby and you call ‘puts’ in an instance method definition, is an instance of the object the receiver of that call?

E.g.

    class MyClass
      attr_accessor :first_name, :last_name, :size

      # initialize, etc (name = String, size = int)

      def full_name
        fn = first_name + " " + last_name 
        # so here, it is implicitly self.first_name, self.last_name
        puts fn 
        # what happens here?  puts is in the class IO, but myClass 
        # is not in its hierarchy (or is it?)
        fn
      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-06-01T02:25:46+00:00Added an answer on June 1, 2026 at 2:25 am

    Absolutely, the current object is the receiver of the method call here. The reason why that works is because the Kernel module defines a puts method and is mixed into Object, which is the implicit root class of every Ruby class. Proof:

    class MyClass
      def foo 
        puts "test"
      end
    end
    
    module Kernel
      # hook `puts` method to trace the receiver
      alias_method :old_puts, :puts
      def puts(*args)
        p "puts called on %s" % self.inspect
        old_puts(*args)
      end
    end
    
    MyClass.new.foo 
    

    This prints puts called from #<MyClass:0x00000002399d40>, so the MyClass instance is the receiver.

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

Sidebar

Related Questions

I have an instance of a NSObject class that is supposed to parse a
We are looking to have Sender and Receiver attributes for each micropost that is
Say I have a singleton-ish, factory-ish, reflection-ish class that receives some input, and spits
I'm defining a class that extends Ext.form.Panel but none of the fields appear when
I created a TreeListCtrl in wxPython like following. self.tree = wx.gizmos.TreeListCtrl(self, style = wx.TR_DEFAULT_STYLE
self.logger.info(msg) popinstance=poplib.POP3(self.account[0]) self.logger.info(popinstance.getwelcome()) popinstance.user(self.account[1]) popinstance.pass_(self.account[2]) try: (numMsgs, totalSize)=popinstance.stat() self.logger.info(POP contains + str(numMsgs) + emails)
[[self enclosingScrollView] setHorizontalLineScroll:0]; the above api doesnt works. Help Appreciated...
[[self mainFrame] loadHTMLString:@<html><body><link href='main.css' rel='stylesheet' type='text/css' /></body></html> baseURL:nil]; I am trying to load a
self.myArray = [NSArray arrayWithObjects: [NSArray arrayWithObjects: [self generateMySecretObject], [self generateMySecretObject],nil], [NSArray arrayWithObjects: [self generateMySecretObject],
self.mood_scale = { '-30':Panic, '-20':'Fear', '-10':'Concern', '0':'Normal', '10':'Satisfaction', '20':'Happiness', '30':'Euphoria'} I need to set

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.