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.

Aliasing Question

Hi, I've been trying lately to alias a particular type of method but didn't know the exact syntax for it, so basically all I've been doing is guessing. I need help aliasing a method like so...
Code:
def example=(n)
  @n = n
end

I wasn't sure of how I would alias something like that. I've tried these different ways, but wasn't right, obviously, I wouldn't be posting this if they were.
Code:
alias old_example example
def example=(n)
  old_example=(n)
  @n = n
end

Code:
alias old_example example
def example=(n)
  old_example(n)
  @n = n
end

If done this way, then I believe that the argument can't be adding to or subtracting from the original code, at least from what I understand.
Code:
alias old_example example
def example=(n)
  old_example = n
  @n = n
end
 

Zeriab

Sponsor

Code:
  def example=(n)
    @n = n
  end
  
  alias old_example example=
  def example=(n)
    old_example(n)
    @n = n
  end

Code:
  def example=(n)
    @n = n
  end
  
  alias old_example= example=
  def example=(n)
    self.old_example = n
    @n = n
  end
 
This is the right syntax:

Code:
alias old_example example
def example=(n)
  old_example=(n)
  @n = n
end

but then you'd have:

Code:
 def example=(n)
@n = n
@n = n
end

Doen't make much sene, but then I don't know what you're trying to do.
 

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