You can do something like that without overwriting a method's function with the alias syntax. What does alias do? It allows you to add to an existing method without overwriting it. For a good number of examples, I'd recommend looking at the various scripts done by Blizzard in the scripts database. The alias syntax works like this. You alias the old method name with a new name, preferably similar to the old name, and then call the new name inside the method. You MUST call the aliased name within the method that was aliased. Now for a little specific detail on when to use the aliased name and what happens when you do. If there are any arguments in the method name, you must have them with the new alias name when you call it. Look at my second example and you should understand aliases involving arguments.
class Foo
def int
number = 7
end
end
class Foo
alias new_int_method int
def int
new_int_method#here you are calling the alias name
if number == 7
p number
end
end
end
As you can see here, we added an "if" conditional branch to the method int. Where would the conditional branch be when the alias "merges" the little pieces of code? Everything AFTER the alias name is called is put at the end of the original method. Unfortunately, I don't know where everything before the alias name goes when the alias name is being called. Now for a working example for you to pick apart and to help you understand aliases a little better. The purpose of this little script is to add the attribute luck to the character's stats through the use of the alias syntax.
class Game_Actor
attr_accessor :luck
#allows the instance variable @luck to be called like a method with $game_actor[ACTOR_ID].luck
alias shinami_setup setup
def setup(actor_id)
shinami_setup(actor_id)
@luck = rand(100)
end#of aliased "def setup(actor_id)"
end#of class Game_Actor
If you have any other questions, please ask them.