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

  • Home
  • SEARCH
  • 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 8667987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:06:17+00:00 2026-06-12T18:06:17+00:00

In Java, I am used to writing an abstract class that does some setup

  • 0

In Java, I am used to writing an abstract class that does some setup work and then delegates to the concrete class like this:

public abstract class Base {
    public void process() {
        // do some setup
        //...

        // then call the concrete class
        doRealProcessing();
    }
     
    protected abstract void doRealProcessing();
}

public class Child extends Base {
    @Override
    protected void doRealProcessing() {
        // do the real processing
    } 
}

I am having a hard time doing this in Ruby because I don’t have abstract classes or methods. I also read that "you aren’t supposed to need abstract classes or methods in Ruby and that I should stop trying to write Java in Ruby".

I would love to know what is the right way to implement the equivalence in Ruby?

  • 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-12T18:06:18+00:00Added an answer on June 12, 2026 at 6:06 pm

    Welcome to dynamically typed languages! You were probably nervous about just defining some function that wasn’t declared anywhere. Don’t be worried. It is very easy:

    class Base
      def process
         # ...
         real_processing
      end
    
      def real_processing    # This method is optional!
        raise "real_processing not implemented in #{self.class.name}"
      end
    end
    
    class Child < Base
       def real_processing
         # ...
       end
    end
    
    b = Child.new
    b.process
    

    EDIT: Here’s another option for you which avoids the need to have two different method names:

    class Base
      def process
        # ...
      end
    end
    
    class Child < Base
      def process
        # ...
        super   # calls the process method defined above in Base
        # ...
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm used to Java so when i try to so something like this: function
I'm writing a Java program that will be used on both Windows and Mac.
I'm writing a Java class that connects to a server and reads messages in
I'm writing some web UI pages that can be used to create Linux user
Is there a Java library that reads configuration files like those pseudo-XML used by
I am writing a class in Java which is used to greatly simplify the
I have used Rhino.Mocks extensively currently writing some tests in Java using EasyMocks. However
I have got to know that src/test/java is used for writing unit tests. I
i used java reflections to get methods from a class(loaded those classes).Now i want
I have a jar library. I used Java Class File Editor (CE) to modify

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.