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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:55:35+00:00 2026-06-06T17:55:35+00:00

I try to write DSL class Warcraft class << self def config unless @instance

  • 0

I try to write DSL

class Warcraft 
  class << self
    def config
      unless @instance
        yield(self)
      end
      @instance ||= self
    end

    attr_accessor :name, :battle_net

    def game(&block)
      @instance ||= Game.new(&block)
    end
  end

  class Game
    class << self
      def new
        unless @instance
          yield
        end
        @instance ||= self
      end

      attr_accessor :side, :hero

      def rune_appear_every(period)
        @rune_appear_every = period
      end

    end
  end
end

Warcraft.config do |war|
  war.name = "Warcraft III"
  war.battle_net = :iccup

  war.game do |game|
    game.side = :sentinels
    game.hero = "Furion"
    game.rune_appear_every 2.minutes
  end
end

And i get such error:

dsl.rb:41:in `block (2 levels) in <main>': undefined method `side=' for nil:NilClass (NoMethodError)
  • 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-06T17:55:37+00:00Added an answer on June 6, 2026 at 5:55 pm

    The issue is here:

      def new
        unless @instance
          yield
        end
        @instance ||= self
      end
    

    You’re not passing in any argument when you yield, later on when you call:

     war.game do |game|
    

    The game variable is nil. So instead of just doing yield, do yield self.

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

Sidebar

Related Questions

I try to write a javascript Self-Executing Anonymous Function window.App = window.App || {}
I'm trying to write a DSL that allows me to do Policy.name do author
I try to write a wrapper class for leveldb. Basically the part of the
I try to write a class that takes a tuple of functions as its
I try to write KSH script for processing a file consisting of name-value pairs,
I try to write and read object of class into and from binary file
So, I am try to write a simple base Exception class for C++, based
try to write a composite component that allows mutltiple text inputs. I read that
I try to write Activator action for changing current song rating. I now that
I try to write a Facebook app. This app will communicate with a rfid

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.