Common Ruby Idioms

前端 未结 15 1999
星月不相逢
星月不相逢 2020-12-07 07:13

One thing I love about ruby is that mostly it is a very readable language (which is great for self-documenting code)

However, inspired by this question: Ruby Code ex

15条回答
  •  庸人自扰
    2020-12-07 07:25

    This slideshow is quite complete on the main Ruby idioms, as in:

    • Swap two values:

      x, y = y, x

    • Parameters that, if not specified, take on some default value

      def somemethod(x, y=nil)

    • Batches up extraneous parameters into an array

      def substitute(re, str, *rest)

    And so on...

提交回复
热议问题