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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:58:09+00:00 2026-06-13T12:58:09+00:00

Suppose you have the following Ruby classes: class A def self.greet puts ‘hi’ end

  • 0

Suppose you have the following Ruby classes:

class A
  def self.greet
    puts 'hi'
  end
end

class B < A; end;
class C < B; end;

Is it possible to redefine greet on B in such a way that C still uses the original definition without modifying C?

(I understand that “you’re doing it wrong” is a probable reaction, but please assume for a moment that there’s a good reason for doing this.)

Update

It’s good to see yet another demonstration that Ruby will let you do whatever you want. However, to anyone finding this question and thinking of doing likewise, I should say that I did eventually realize I was doing it wrong; C needed to subclass A directly.

Read on to receive your shotgun, and watch where you’re aiming 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-06-13T12:58:10+00:00Added an answer on June 13, 2026 at 12:58 pm

    You could do something like:

    def B.greet
      puts self == B ? 'beeeee' : super
    end
    

    This means that B is aware that you want to change its version of greet but only for B and no other decedent classes.

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

Sidebar

Related Questions

Suppose we have following code defined in tester.py class Tester( object ): def method(
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have following code: def foo(s): A dummy function foo. For example: >>>
Suppose I have following code def foo(x:Int):Unit = { if (x == 1) println
let's suppose to have following code: <body style=overflow: hidden> <div class=wall> <button>New</button> <div class=prova>
Suppose I have following code: public class CBase: AbstractC,IRenderable { //code here } public
Suppose you have the following file: textfield,datetimefield,numfield foo,2008-07-01 17:50:55.004688,1 bar,2008-07-02 17:50:55.004688,2 The Ruby code
Suppose I have following Class - structure ? class A{ List<B> listB; //getter and
Suppose I have the following code: #!/usr/bin/env ruby -wKU h = {} h[[1, a]]

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.