TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Help me refactor this code please (Ruby)

1 点作者 grover_hartmann将近 10 年前
It&#x27;s basically a vending machine simulation, I want to refactor it into two classes, a model (VendingMachine) and a Controller. I&#x27;m not sure what else to do. Please help.<p>https:&#x2F;&#x2F;gist.github.com&#x2F;anonymous&#x2F;a978dcd30383f3e618e5

2 条评论

grover_hartmann将近 10 年前
So I would like to rename VendingMachine to Controller and have a VendingMachine model where I move #vend and #refund to it.<p>I&#x27;m also not very happy with #menu being this large in LoC. What would you guys recommend?
评论 #10095302 未加载
technion将近 10 年前
Think about types. You call .to_i on the balance, so it can only initially be an integer. But you have items costing 1.50.