ruby - Ruby 的虚拟属性和继承超级
问题描述
我正在复习红宝石基础知识,但讲师提供的一些代码不起作用。有人可以解释一下缺少什么以及为什么需要缺少什么吗?非常感谢
class Probe
def deploy(deploy_time, return_time)
puts "Deploying"
end
end
class MineralProbe < Probe
def deploy(deploy_time)
puts "Preparing sample chamber"
super(deploy_time, Time.now + 2 * 60)
end
end
Mineralprobe.new.deploy(Time.now)
我得到的错误是这样的: C:\Ruby26-x64\bin\ruby.exe C:/Users/-/RubymineProjects/test1/probe.rb Traceback (最近一次调用最后):C:/Users/-/ RubymineProjects/test1/probe.rb:14:in `': uninitialized constant Mineralprobe (NameError) 你的意思是?矿物探针
进程以退出代码 1 结束
解决方案
有一个简单的类型,该类被称为
class MineralProbe < Probe
^
但你尝试初始化一个实例
Mineralprobe.new.deploy(Time.now)
^
推荐阅读
- python - 如何提高网络图可视化?
- android - 如何在片段中创建具有动态行的表格布局
- c# - 访问方法的返回参数类型数组
- azureservicebus - microsoft.servicebus.messaging.queueclient.acceptmessagesessionasync 中的属性“isExclusiveMode”有什么作用
- ios - 如何裁剪屏幕截图的特定部分?
- python - 如何使用熊猫转置行和列?
- javascript - 如何检查 iframe 是否有文本或 pdf
- python - Python:在多行/多列上扩展 python subplots()
- c# - 应用在任务栏中打开的选项卡过多
- javascript - 无法通过 AJAX 请求捕获来自服务器的响应