关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭8年前。Improvethisquestion在我问这个问题之前,我浏览了SO上“RubyonRails”的搜索结果。找不到太多,但以下(foundonthispage)让我觉得很有趣Personally,Istartedusing.html,movedontophp,triedruby(hatedit),discoveredPython/DJango..andhavebeenhappyeversince.这就是交易。我个人目前还没有
我在这里尝试按照最小意外原则工作...假设您有一个接受两个对象的方法。该方法需要这些是对象实例,但在您初始化类的地方,您可能只有引用ID。例如,这在网络服务的路由器/Controller中很常见。设置可能看起来像这样:post"/:foo_id/add_bar/:bar_id"doAddFooToBar.call(...)end有许多不同的方法可以解决这个问题。对我来说,这里最“惯用的”是这样的:defAddFooToBar.call(foo:nil,foo_id:nil,bar:nil,bar_id:nil)@foo=foo||Foo[foo_id]@bar=bar||Bar[bar
我一直在看maxmethod在Ruby的Enumerable混合(v2.4.1)。这是一个相当简单的方法,但是当存在重复项时它如何排序项目有点令人困惑。例如:x=[1,2,3,4,5,6,7,8,9]x.max{|a,b|a%2b%2}=>110.times{|y|px.max(y){|a,b|a%2b%2}}[][1][1,7]#whyis7thenextelementafter1?[3,1,5]#whynomore7?[7,3,1,5]#7isnowfirst[9,7,3,1,5][9,7,3,1,5,6][9,7,3,1,5,4,6][9,7,3,1,5,2,4,6][9,7,5