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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:18:41+00:00 2026-06-14T22:18:41+00:00

I have an instance method defined on a class: class Foo def is_linux #

  • 0

I have an instance method defined on a class:

class Foo
  def is_linux
    # some code...
    # returns true or false
  end
end

And i would like to call this method in a Module:

class Foo
  module Dog
    is_linux? ? puts "Is Linux" : puts "Is Windows"
  end
end

This gives me the following error:

NoMethodError: undefined method `is_linux?' for Foo::Foo:Module

I know i can write

class Foo
  module Dog
    Foo.new.is_linux? ? puts "Is Linux" : puts "Is Windows"
  end
end

But i was wondering if there is a way for the module to access the current instance?

  • 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-14T22:18:43+00:00Added an answer on June 14, 2026 at 10:18 pm

    Basically you’ll need somehow to “share” your utility methods.

    I would suggest to put them into a mixin:

    module Mixin
      def is_linux?
        true
      end
    end
    
    class Foo
      include Mixin # adding methods at instance level
    end
    
    class Foo
      module Dog
    
        extend Mixin # adding methods at class level
    
        puts is_linux? ? "Is Linux" : "Is Windows"
    
      end
    end
    
    #=> Is Linux
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have for example a class with instance method and variables class Foo
I have following code: class Foo(object): def __init__(self): baz=self.bar(10) @staticmethod def bar(n): if n==0:
If I have the following code in a class method defined on the association.
I have a method where I would like to return an object instance of
I have a static method defined in a base class, I want to override
So I have a class defined in Foo.h, implemented in Foo.m. I then have
I have written the following class: class myClass(object): def __init__(self): pass def foo(self, arg1,
I have this question on a homework assignment: The method foo() defined in the
Say I have a class in Python that has an eq method defined for
I have the following defined: #!/usr/bin/env ruby class Something def self._attr_accessor key, value, type

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.