TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

1 pointsby grover_hartmannover 9 years ago
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 comments

grover_hartmannover 9 years ago
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 未加载
technionover 9 years ago
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.