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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:17:30+00:00 2026-05-25T02:17:30+00:00

I’m writing a small gem, and I want to define a DSL-like method, pretty

  • 0

I’m writing a small gem, and I want to define a DSL-like method, pretty much the same as the desc and task methods in Rake.

Rake defines them as private methods in the Rake::DSL module and then

self.extend Rake::DSL

to mix the module into the main object? (I’m a newbie and go ahead laugh if I’m wrong)

what are the benefits by doing so? is it because making these methods private can prevent any other objects to use them (that is, to prevent something like some_obj.desc) ?

what if I define the methods in Kernel

module Kernel
  private

  include Rake::DSL
end

Is there any difference?

  • 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-25T02:17:31+00:00Added an answer on May 25, 2026 at 2:17 am

    Just to extend the answer given by bor1s, about the private methods:

    In ruby you have “private” and “protected” methods. What bor1s says, is correct when talking about “protected” methods. Declaring a method “private” additionally prevents other instances of the same class from using the method.

    When you call a “private” method, you cannot use a dot in front of it – you cannot even use self., even though using or omitting self has usually the same effect.

    class Xyzzy
      private
      def foo
        puts "Foo called"
      end
    
      public
      def do_it
        foo       # <= Is OK
        self.foo  # <= raises NoMethodError
      end
    end
    
    Xyzzy.new.do_it
    

    If you change ‘private’ to ‘protected’ in the code above, no error will be raised.

    And about modules:

    The final result of defining a method in Kernel and extending Kernel with the method defined in some module is the same: in both cases the method is global.

    Using a module is just a little more elegant, as it groups your changes in one place, but I would say it’s a matter of personal taste.

    Usually you do not include methods in Kernel or Object (as it may be a little dangerous), but you include (or extend) a specific class or object which needs these methods, and in this case you need your methods grouped in a module.

    Even Rake in version 0.9.0 stopped including the DSL commands in Object:

    == Version 0.9.0

    • Incompatible *change*: Rake DSL commands (‘task’, ‘file’, etc.) are
      no longer private methods in Object. If you need to call ‘task :xzy’ inside
      your class, include Rake::DSL into the class. The DSL is still available at
      the top level scope (via the top level object which extends Rake::DSL).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.