我认为在类中包含一个模块作为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'
我想知道为什么我在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)