坚持使用LearnStreet Ruby培训.简单的Ruby代码
尝试使用新的LearnStreet在线教程学习
Ruby.
试图通过他们的Q& A系统获得帮助,但似乎没有人回答他们.
这个问题和我得到了两个提示
我的尝试是 def account.widthdraw! @balance = @balance - amount end account.withdraw!(100) 我缺少什么想法? 解决方法
一步一步来: >“你现在可以在帐户对象上实现withdraw!方法吗? class Account def withdraw! end end >需要一个参数量… class Account def withdraw!(amount) end end >并减少指定金额的余额? class Account def withdraw!(amount) @balance = @balance - amount end end >在定义方法后,继续从账户中提取100美元并检查余额.“ account = Account.new account.withdraw!(100) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |