小编d0b*_*0bz的帖子

使用模块和继承调用"超级"关键字

我认为在类中包含一个模块作为mixin"将函数添加到"类中.

我不明白为什么这不能按预期工作:

module A
    def blah
        super if defined?(super)
        puts "hello, world!"
    end
end

class X
    include A
end

class Y < X
    include A
end

y = Y.new
y.blah
Run Code Online (Sandbox Code Playgroud)

我期待"y"调用它的超级blah()(因为它包含在X类中?)但我得到了:

test.rb:3:in blah:super:没有超类方法`blah'

ruby inheritance module super mixins

4
推荐指数
1
解决办法
1226
查看次数

在PHP中序列化引用

我想知道为什么我在php中的序列化不能按预期工作:

<?
$x = "whatever...";
$y = array(&$x, "test, 1-2, 1-2...", &$x);
$yy = unserialize(serialize(&$y));
$y[0] = "blah";
echo($yy[0]); // prints 'whatever', was expecting 'blah'
?>
Run Code Online (Sandbox Code Playgroud)

php serialization reference

3
推荐指数
1
解决办法
1378
查看次数

标签 统计

inheritance ×1

mixins ×1

module ×1

php ×1

reference ×1

ruby ×1

serialization ×1

super ×1