Oké, so we want the following thing to happen: We want 4 pop-ups to pop up:
Yay, it works == Hello world == this is my first script == roxors.
We could do this by doing the folowing:
[color=blue]class[/color] [color=darkblue]MyFirstScript[/color]
[color=blue]def[/color] [color=darkblue]initialize[/color]
p [color=purple]"Yay, it works"[/color]
p [color=purple]"Hello world"[/color]
p [color=purple]"This is my first script"[/color]
p [color=purple]"Roxors"[/color]
[color=blue]end[/color]
[color=blue]end[/color]
Now, you probably understand that this is not what we wanted. we REWROTE the init method, instead of ADDING code to it. So Let's Alias!
[color=blue]class[/color] [color=darkblue]MyFirstScript[/color]
[color=blue]alias[/color] the_old_init initialize
[color=blue]def[/color] [color=darkblue]initialize[/color]
p [color=purple]"Yay, it works"[/color]
the_old_init
p [color=purple]"Roxors"[/color]
[color=blue]end[/color]
[color=blue]end[/color]
Whoaha, lets see what we just did!.
1:
class MyFirstScript
2:
alias the_old_init initialize
3:
def initialize
4: p
"Yay, it works"
5: the_old_init
6: p
"Roxors"
7:
end
8:
end
Line
2. Here we created the alias. The name of the alias is
the_old_init and the reference object (the method to alias) is called
initialize.
Line
4. Here we made a print object. We wanted to pop-up
yay ot works as first.
Line
5. So we called the alias: the old init. To include the original code, you simply put in the alias name, like it was a method name, wich it is in fact. At line five the originial content of def
initialize is included.
Line
6. Another Print Object, this time with
roxors.
Yay, you just made your first alias. :lol: