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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ruby Tricks

47 点作者 vijaydev超过 15 年前

5 条评论

petercooper超过 15 年前
Just want to note, as the author, that this post is almost 18 months old now and I don't necessarily stand by them all anymore ;-) (I'd need to go back and re-edit to make <i>that</i> assertion..)
评论 #811939 未加载
评论 #811980 未加载
gommm超过 15 年前
Careful with one of those tips [* x] does return x if x is an array and [x] otherwise except in the case where x is a hash in which case it transforms the hash to an array. Eg:<p>x = {:a =&#62; 1, :b =&#62; 2}<p>[* x]<p>=&#62; [[:a, 1], [:b, 2]]<p>Some of the other tips just make the code less readable
评论 #811731 未加载
chasingsparks超过 15 年前
I often do the %w{rubygems sinatra etc}.each{|lib| require lib} trick. If I were more motivated, I would submit a patch that would allow require to take an array.
评论 #812350 未加载
blasdel超过 15 年前
A trick is something a whore does for money, not something that improves your code.
axod超过 15 年前
<p><pre><code> &#62;&#62; 3. Format decimals &#62;&#62; money = 9.5 &#62;&#62; "%.2f" % money # =&#62; "9.50" </code></pre> Seriously? IMHO These sorts of things are not nice. To read the code you have to know these special magic operators. It's not immediately obvious it's calling a function to do string formatting.<p>Readable code is so important :/
评论 #811926 未加载