以下引用Iselia雪于2008-3-20 19:26:20的发言:
以下引用沉影不器于2008-3-20 19:22:12的发言:
伪变量,不晓得算不算实例?
伪变量是啥意思?
假如制作一个有特殊效果的Sprite,以Rpg::Sprite为父类。
class ABC < RPG::Sprite
def initialize
super
self.x = 10
end
end
就是说在初始化时,把这个RPG::Sprite的子类的x坐标设为10,也就是ABC自己的X坐标等于10了。
通常这个东东都在一个class内部使用,修改此class的属性值,如是说。
以下引用水迭澜于2008-3-20 18:36:15的发言:
该对象自身。
例如window_base里的self.x意思就是本窗口的X值
class A
def c
p "c"
end
end
class B < A
def initialize
super()
self.c
end
end
B.new
以下引用禾西于2008-3-20 22:04:17的发言:
class A
def c
p "c"
end
end
class B < A
def initialize
super()
self.c
end
end
B.new
class A
def initialize
p "i"
end
def c
p "c"
end
def d
p "d"
end
end
class B < A
def initialize
super()
self.c
end
def c
super()
end
def d
self.c
end
end
B.new
#=>"i"
#=>"c"
B.new.c
#=>c
B.new.d
#=>c
以下引用禾西于2008-3-21 8:53:00的发言:
其實怎麼說呢,我覺得self.的唯一用途就是繼承的時候調用父類方法而已……==
PS。早上看錯了……原來TERENCE問的是沒有繼承怎麼用……==|||剛起床果然很迷糊。
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |