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

The Archive Base Latest Questions

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

In one of Ruby examples I see the following code: require ‘net/http’ req =

  • 0

In one of Ruby examples I see the following code:

require 'net/http'
req = Net::HTTP::Get.new( "http://localhost:8080/" )
req.basic_auth( "user", "password" )

What is the easiest way to know what Ruby class actually implements this basic_auth method or is it dynamically generated? I have checked public_methods of Net::HTTP::Get and it’s definitely not there. But how to check what class actually implements it?

  • 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-28T13:33:22+00:00Added an answer on May 28, 2026 at 1:33 pm

    Generally, you would use the Kernel#method method to get the Method object for the method in question and then you would use the Method#owner method to ask the Method object where it was defined.

    So,

    req.method(:basic_auth).owner
    # => Net::HTTPHeader
    

    should answer your question.

    Except, in this particular case, that won’t work because req is a Net::HTTP::Get object and Net::HTTP::Get overrides the method method to mean something completely different. In particular, it doesn’t take an argument, thus the above code will actually raise an ArgumentError.

    However, since Net::HTTP::Get inherits from Object and Object mixes in Kernel, it is legal to bind the Kernel#method method to an instance of Net::HTTP::Get:

    Kernel.instance_method(:method).bind(req).(:basic_auth).owner
    # => Net::HTTPHeader
    

    So, there’s your answer: the method is defined in Net::HTTPHeader.

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

Sidebar

Related Questions

I want to write code in Ruby witch net::ssh that run commands one by
I'm struggling to get a regexp (in Ruby) that will provide the following one,
I used textmate to work with ruby code for over one year. Recently I
Am new to ruby. Can any one tell me how to find inverse of
I am new to Ruby on Rails and I'm desperately trying to get a
New to rails/ruby (using rails 3 and ruby 1.9.2), and am trying to get
I have VPS with 1GB of RAM. One ruby-app that runs on thin server
Suppose you have an ActiveRecord::Observer in one of your Ruby on Rails applications -
For some reason, one of my Ruby on Rails classes produces this sort of
In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and

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.