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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:00:26+00:00 2026-05-25T12:00:26+00:00

Or, rather, how do I do it perfectly? This is what I came up

  • 0

Or, rather, how do I do it perfectly?

This is what I came up with so far:

# A double that stands in for a yet-to-be-defined class. Otherwise
# known as "lazy evaluation."
#
# Idea lifted from:
# http://github.com/soveran/ohm/
class Double < BasicObject
  def initialize(name)
    @name = name
  end

  def to_s
    @name.to_s
  end

  alias_method :inspect, :to_s

  def method_missing(mth, *args, &block)
    @unwrapped ? super : @unwrapped = true
    ::Kernel.const_get(@name).send(mth, *args, &block)
  ensure
    @unwrapped = false
  end; private :method_missing
end

This works:

foo = Double(:Foo)  # Now we can safely pass around Foo without 
                    # having initialised it.
foo.class           # Uninitialised constant
                    # That's expected because Foo doesn't exist yet!
class Foo; end      # So there, we shoo it into existence.
foo.class # Foo     # foo indeed is Foo. The sleight of hand of works.

This is what I can’t get to work:

inst = Foo.new
inst.is_a? Foo      # true, of course
inst.is_a? foo      # TypeError: class or module required

Why won’t the double stand in for Foo in the last line?

  • 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-25T12:00:26+00:00Added an answer on May 25, 2026 at 12:00 pm

    There’s nothing wrong with your code – that’s expected behavior. The #is_a? method expects a class or module. Try it with build-in classes and you get the same error:

    str = "a string"
    str.is_a? String
    => true
    
    other_str = "another string"
    str.is_a? other_str
    => TypeError: class or module required
    

    If you want to change that you’ll have to override is_a? (wouldn’t recommend that). More likely, you want to do something like this:

    str.is_a? other_str.class
    => true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rather than scraping a Ruby version of this algorithm off the net I wanted
Rather new to php, so sorry if this seems stupid. I'm really copying a
Rather Trivial Question. So I tried to do this: if (array[0]==some_string) where array is
This question is more aimed at good design practices rather than exceptions and stacks.
I know this isn't exactly a programming question per se, but rather a settings
I have this rewrite rule that turns foo.com/test (or foo.com/test/) into foo.com/test.txt: RewriteRule ^test/?$
I'm aware that is a rather difficult question to answer, mainly because there's so
I'm experiencing a rather strange problem with foreign keys, namely this doesn't work as
I've got into a rather simple, yet annoying problem. I'm trying to create a
Here's a rather dumb but perfectly valid question coming from a newbie. Context: My

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.