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.

[Resolved] Aliasing of a Module

Status
Not open for further replies.
I have problems when aliasing modules methods like: Module.method(For example: Input.press? or Audio.bgm_play)
I try something like:
Code:
module Input
  alias aliasing_input_press Input.press?
  def Input.press?(args)
    aliasing_input_press(args)
  end
end
That throws me a Syntax Error on the line: "alias aliasing_input_press Input.press?"
And if I do:
Code:
module Input
  alias aliasing_input_press press?
  def press?(args) # or def Input. press?
    aliasing_input_press(args)
  end
end
It throw me an "no method press? for Input::Module" error.
And:
Code:
module Input
  alias_method(aliasing_input_press, Input.press?)
  def Input.press?
    aliasing_input_press(args)
  end
end
Throws me a Syntax error.
What shall I do?
 

OS

Sponsor

In the second example, try replacing press? with self.press?. Do it to both press? after the alias and in the name. If that doesn't work, make it alias press?, but keep the method name self.press?

Hope that helps, if not, then sorry.

~Peace!
 
Code:
module YourModuleName
  class << self
    if @yourname_scriptname_stack.nil?
      alias_method :yournewmethodname, :yourmethodname
      @yourname_scriptname_stack = true
    end
    def yourmethodname
      # blah
      yournewmethodname
      # blah
    end
  end
end

Something like that is I believe what you are looking for.
 
should be this:
Code:
module Input
  class << self
  alias_method :aliasing_input_press :press?
  def press?(*args)
    aliasing_input_press(args)
  end
  end
end

and thanks seph, I was needing it, too.
 
Status
Not open for further replies.

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