Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Some questions relating to my ideas on auto-aliasing (w/ stacked_method)

Good day everybody!

I'm not sure if this is more of a question or a brainstorm, but it is something that I would like to hear everybody's thoughts on and how you'd do it, maybe we could just brainstorm and do it together.

I was thinking too hard the other week, like I always do, when I came up with something that sounded like a simple idea, but when I started thinking about the details the 'simple' idea didn't sound so simple anymore... I mean, it probably could be something simple, but I donno, the secret lies within 'alias'... how does alias work exactly? No, I don't mean "Hey I'm a n00b how do I use alias", I'm talking about what is 'alias' really doing when we call it? Like, how exactly does it record the previously named method, rename it and call it upon redefinition accurately? And for that matter, how does the information stack whenever a method is called?

Here's what I was thinking of doing, I was thinking of making an alternative/replacement to alias and alias_method calls, by creating a new method called the 'stacked_method'. With this method, it would almost be like an 'auto-alias' without the need for making an alias name, matter of fact I want to make it where you don't have to do NOTHING at all but call a 'stacked_method(?)' within a method redefinition (not previous to it or nothing).

[spoiler='alias/alias_method' call]
Code:
def method
  # ...very initial/previous stack of code
end

alias_method, :old_method, :method

def method
  # ...
  old_method
end
[/spoiler]

Compared to...

[spoiler='stacked_method' call]
Code:
def method
  # ...Very initial/previous stack of code
end

def method
  # ...
  stacked_method(method)
end
[/spoiler]

But then that also leads to the question, how would you auto-log definitions? For instance, how would you auto-log the default Game_Battler initialze method without touching the default script? This is something you might want to think about too, because I'd like to hear your input on these questions/ideas.

I have my own twisted version that I came up with in my head, it almost sounds kinda evil though and a little harder than it should be, thats why I want to hear what you'd do if you were to try and do this, and your knowledge as it is on stuff like this.
 
Cool beans, I'm going to play around with that test code and see if there's something I can do with it, thank you for linking me to it.

There's no way to redefine 'def' either directly or indirectly is there? I was more than aware of the issue of the 'method' being redefined the second you call 'def', I wonder if there is a way to make 'def' log a method after the very last line of code within that method... is there a way to redefine/alias 'def'?

I'll check out define_method() and see what happens when I alias it, although that might or might not do anything its worth a try.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top