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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:34:51+00:00 2026-05-16T11:34:51+00:00

I wonder if there are cheat cheets for all design patterns implemented in Ruby

  • 0

I wonder if there are cheat cheets for all design patterns implemented in Ruby so that you don’t have to reinvent the wheel.

  • 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-16T11:34:52+00:00Added an answer on May 16, 2026 at 11:34 am

    Design patterns are useful for organizing massive amounts of code. since you don’t need to write as much code to do things in ruby as you do in #{verbose_algol_derivitive_language}, they don’t have the same degree of importance.

    What you will see used all the time is strategy and builder implemented with blocks (an example of builder would be form_for blocks in rails views, an example of strategy would be File.open) I can’t really think of the last time I saw any others (gof patterns anyways)

    EDIT: responding to

    You mean with ruby we don’t have to
    think about design patterns in most
    cases? Another question, if I’m using
    Rails, do I actually have to think
    about design patterns? Cause I don’t
    know where to use them. They don’t
    seem to fit in any component of the
    MVC. Are design patterns only for
    people that are building massive
    libraries/frameworks eg. Rails,
    DataMapper, MongoID etc and not for
    others that only using these
    frameworks/libraries?

    For the most part, rails makes a lot of your decisions for you, and will until your app hits a fairly high level of complexity. Even if you are using something like sinatra though (which doesn’t decide anything for you), you still won’t really need to reach for those GoF patterns the same way as you would in a language like (for example) java.

    This is because the whole point of design patterns is bottled ways to keep things flexible and maintainable. If that is built into the language, often they aren’t even needed.

    For example, a strategy pattern implemented in java looks sort of like this

    //StrategyExample test application
    
    class StrategyExample {
    
        public static void main(String[] args) {
    
            Context context;
    
            // Three contexts following different strategies
            context = new Context(new ConcreteStrategyAdd());
            int resultA = context.executeStrategy(3,4);
    
            context = new Context(new ConcreteStrategySubtract());
            int resultB = context.executeStrategy(3,4);
    
            context = new Context(new ConcreteStrategyMultiply());
            int resultC = context.executeStrategy(3,4);
    
        }
    
    }
    
    // The classes that implement a concrete strategy should implement this
    
    // The context class uses this to call the concrete strategy
    interface Strategy {
    
        int execute(int a, int b);
    
    }
    
    // Implements the algorithm using the strategy interface
    class ConcreteStrategyAdd implements Strategy {
    
        public int execute(int a, int b) {
            System.out.println("Called ConcreteStrategyAdd's execute()");
            return a + b;  // Do an addition with a and b
        }
    
    }
    
    class ConcreteStrategySubtract implements Strategy {
    
        public int execute(int a, int b) {
            System.out.println("Called ConcreteStrategySubtract's execute()");
            return a - b;  // Do a subtraction with a and b
        }
    
    }
    
    class ConcreteStrategyMultiply implements Strategy {
    
        public int execute(int a, int b) {
            System.out.println("Called ConcreteStrategyMultiply's execute()");
            return a * b;   // Do a multiplication with a and b
        }
    
    }
    
    // Configured with a ConcreteStrategy object and maintains a reference to a Strategy object
    class Context {
    
        private Strategy strategy;
    
        // Constructor
        public Context(Strategy strategy) {
            this.strategy = strategy;
        }
    
        public int executeStrategy(int a, int b) {
            return strategy.execute(a, b);
        }
    
    }
    

    It is a lot of work, but what you end up with is worth it a lot of the time, and can be the difference between a big ball of mud, and something that has a chance in hell of being maintained. Now lets do it in ruby

    class Context
      def initialize(&strategy)
        @strategy = strategy
      end
    
      def execute
        @strategy.call
      end
    end
    
    
    
    a = Context.new { puts 'Doing the task the normal way' }
    a.execute #=> Doing the task the normal way
    
    b = Context.new { puts 'Doing the task alternatively' }
    b.execute #=> Doing the task alternatively
    
    c = Context.new { puts 'Doing the task even more alternatively' }
    c.execute #=> Doing the task even more alternatively
    

    its hard to even call that a pattern, you are just using blocks! When the language covers the needs that the pattern addresses, effectively using the language will mean you don’t really need the pattern in most circumstances. It also means you can elegantly address that kind of problem when it would be horrible overkill to do a java style strategy.

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

Sidebar

Related Questions

Wonder if there is a js plugin to control music volume? I have all
I wonder if there will be some API or web service that given a
I wonder if there is a service where I can clean-up html-code so that
I wonder if there is any trick to solve this problem. I have my
I wonder if there are many servers that are supporting CORS?
I wonder if there is an elegant way to derive all compositions of 2n
i wonder if there is any way to call an asp method that returns
I wonder if there's a way to do the following: I have a structure
I wonder is there have a way to set mp3 files in ListView as
I wonder if there is a 'local runtime environment' for hosting Javascript code, that's

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.