开发者

Shorten way to write code and respect DRY

I wonder if this code

-matches.each do |match|
    开发者_运维百科=match.clan_1.name
    =match.score(clan_1)
    =match.clan_2.name
    =match.score(clan_2)

can become something like this:

-matches.each do
    =clan_1.name
    =score(clan_1)
    =clan_2.name
    =score(clan_2)

I think it will be much more DRY. Any ideas?


The answer is:

-matches.each do |match|
    -match.instance_eval do
        =clan_1.name
        =score(clan_1)
        =clan_2.name
        =score(clan_2)


The best way to DRY this up would be to stick it in a helper method and call that from your views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜