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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:30+00:00 2026-05-27T11:38:30+00:00

Stackoverflowers! I’ve recently begun dabbling in Ruby, and I have a few questions. First

  • 0

Stackoverflowers!

I’ve recently begun dabbling in Ruby, and I have a few questions. First some background: I’m used to C++ and Java inheritance, and have always had a dislike for how inheritance works there in many game-related scenarios (say, a roguelike, for example). Mainly due to it being hard to encapsulate behaviour in a good way. For examples, in Java: (not that I’d implement it this way, but it was the best example I could come up with on short notice.)

Actor extends GameObject
Creature extends Actor

FlyingCreature extends Creature
Dragon extends FlyingCreature

Humanoid extends Creature

…so far so good, right? But what if I decided to implement a class “Gargoyle” (winged humanoid)? Then it would belong to both FlyingCreature and Humanoid — so I’d have to encapsulate one of the traits and then refactor it or something.

The ideal solution — personally — would be if there were some effective way to extract the unique attributes/functionality into encapsulated objects, and then have every GameObject be a composition of different modularized components that can interact with each other. (With no inheritance besides eventualities such as Item:GameObject, Actor:GameObject, Tile:GameObject — if even then).

So that a specific GameObject (say, an orc) can be easily created by kinda creating a tree of components — something crudely like this but more flexible:

          [Actor]
[Organic]/  |    \[Persona] // Name, etc..
            |          \
       [Humanoid]      [Intelligence] // AI or PlayerController
            |
       [Inventory] // [ArrayList of items...]
            |
       [Equipment] // [Hash of :slot -> Item]

But more to the point: As I started learning about Ruby, I learned about it’s meta-programming abilities, it’s runtime freedom due to the language’s reflection, and the extend/include capabilities of modules. So I figured that if I divided specific traits into modules (and made sure to have careful naming policies and such), then I could allow my classes to include behaviour according to context and events. For example, let’s say I have a dwarf — named Bob O’Copp — and he trips on a tiny vampire piglet while spelunking in some dark sewer dungeon. And thus he falls into some magichemical puddle that mutates him — giving him cute fairy wings. But since dwarves aren’t normally avian, his class wouldn’t have the functionality of flight. But for this instance, it would be a valid trait. Thus, I figured that “bob.extend Flight” would be an excellent solution to the issue.

But what if one of the traits is temporal? Let’s say Bob O’Copp finds a scroll that summons magical wings on his back for the duration of the spell… But. After a lot of googling I’ve yet to find any good information as to how to retract/un-extend nor exclude mixins after it’s been applied — if at all practically possible. And since there’s a lot of really smart and experienced programmers here, so I’d like to formally implore you to bestow some of your magnificent insight, O mighty bearded oracles! 🙂

So… a few questions:

  • Am I delusional to want to use mixins this way?
  • Is there some big drawback I haven’t thought of?
  • Is it at all possible to retract a mixin once applied?
  • Do you have any other recommendations for a good way to deal with the issue? (giving me a direction in the form of some keywords would sufficient)

Eagerly awaiting any replies with anticipation

Great thanks in advance,

-Robocopulate

  • 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-27T11:38:31+00:00Added an answer on May 27, 2026 at 11:38 am

    Am I delusional to want to use mixins this way?
    I don’t think that you are delusional. Temporary mixins sounds like a neat way to describe your goals.

    Is there some big drawback I haven’t thought of?
    Not that is obvious to me after a short bit of reflection, except (see next question)…

    Is it all possible to retract a mixin once applied?
    Not in unmodified Ruby. There are various proposals for adding unextend or similar, but none have yet been added to the official language.

    However, there is the Remix library, which gives you both unextend and temp_include and more. If you’re going to run somewhere that Remix is available, you can use that.

    Do you have any other recommendations for a good way to deal with the issue?
    You could always roll your own inheritance system. 😐 For example, create module functions that accept an instance to operate upon (possibly using instance_eval to violate its encapsulation and store custom data) and then keep track of whether or not a particular module is available.

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

Sidebar

Related Questions

hey stackoverflowers. im having a few problems with the code i have written to
Stackoverflowers, I have a resultset from a SQL query in the form of: Category
Greetings Stackoverflowers, I have an application in which a communication abstraction layer exists. Each
I'm relatively new to Java EE and have already began to hear about the
Hello Fellow stackoverflowers, I´m stuck writing a piece of code. I have application with
In my Java app I have a template string, say, This record's name is
I have a string that contains some values I need to extract. Each of
We have an API that will be only used by our new website for
G'day Stackoverflowers, I'm the author of Perl's autodie pragma, which changes Perl's built-ins to
You're my last hope stackoverflowers.

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.