[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7802":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":16,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":19,"topics":21,"createdAt":10,"pushedAt":10,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":16,"starSnapshotCount":16,"syncStatus":25,"lastSyncTime":26,"discoverSource":27},7802,"ruby","airbnb\u002Fruby","airbnb","Ruby Style Guide","",null,"Ruby",3888,757,277,15,0,30.64,"MIT License",false,"main",[],"2026-06-12 02:01:44","# Ruby Style Guide\n\nThis is Airbnb's Ruby Style Guide.\n\nIt was inspired by [GitHub's guide](https:\u002F\u002Fweb.archive.org\u002Fweb\u002F20160410033955\u002Fhttps:\u002F\u002Fgithub.com\u002Fstyleguide\u002Fruby) and [RuboCop's guide][rubocop-guide].\n\nAirbnb also maintains a [JavaScript Style Guide][airbnb-javascript].\n\n## Table of Contents\n  1. [Whitespace](#whitespace)\n      1. [Indentation](#indentation)\n      1. [Inline](#inline)\n      1. [Newlines](#newlines)\n  1. [Line Length](#line-length)\n  1. [Commenting](#commenting)\n      1. [File\u002Fclass-level comments](#fileclass-level-comments)\n      1. [Function comments](#function-comments)\n      1. [Block and inline comments](#block-and-inline-comments)\n      1. [Punctuation, spelling, and grammar](#punctuation-spelling-and-grammar)\n      1. [TODO comments](#todo-comments)\n      1. [Commented-out code](#commented-out-code)\n  1. [Methods](#methods)\n      1. [Method definitions](#method-definitions)\n      1. [Method calls](#method-calls)\n  1. [Conditional Expressions](#conditional-expressions)\n      1. [Conditional keywords](#conditional-keywords)\n      1. [Ternary operator](#ternary-operator)\n  1. [Syntax](#syntax)\n  1. [Naming](#naming)\n  1. [Classes](#classes)\n  1. [Exceptions](#exceptions)\n  1. [Collections](#collections)\n  1. [Strings](#strings)\n  1. [Regular Expressions](#regular-expressions)\n  1. [Percent Literals](#percent-literals)\n  1. [Rails](#rails)\n      1. [Scopes](#scopes)\n  1. [Be Consistent](#be-consistent)\n  1. [Translation](#translation)\n\n## Whitespace\n\n### Indentation\n\n* \u003Ca name=\"default-indentation\">\u003C\u002Fa>Use soft-tabs with a\n    two-space indent.\u003Csup>[[link](#default-indentation)]\u003C\u002Fsup>\n\n* \u003Ca name=\"indent-when-as-case\">\u003C\u002Fa>Indent `when` as deep as `case`.\n    \u003Csup>[[link](#indent-when-as-case)]\u003C\u002Fsup>\n\n    ```ruby\n    case\n    when song.name == 'Misty'\n      puts 'Not again!'\n    when song.duration > 120\n      puts 'Too long!'\n    when Time.now.hour > 21\n      puts \"It's too late\"\n    else\n      song.play\n    end\n\n    kind = case year\n           when 1850..1889 then 'Blues'\n           when 1890..1909 then 'Ragtime'\n           when 1910..1929 then 'New Orleans Jazz'\n           when 1930..1939 then 'Swing'\n           when 1940..1950 then 'Bebop'\n           else 'Jazz'\n           end\n    ```\n\n* \u003Ca name=\"align-function-params\">\u003C\u002Fa>Align function parameters either all on\n    the same line or one per line.\u003Csup>[[link](#align-function-params)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    def self.create_translation(phrase_id, phrase_key, target_locale,\n                                value, user_id, do_xss_check, allow_verification)\n      ...\n    end\n\n    # good\n    def self.create_translation(phrase_id,\n                                phrase_key,\n                                target_locale,\n                                value,\n                                user_id,\n                                do_xss_check,\n                                allow_verification)\n      ...\n    end\n\n    # good\n    def self.create_translation(\n      phrase_id,\n      phrase_key,\n      target_locale,\n      value,\n      user_id,\n      do_xss_check,\n      allow_verification\n    )\n      ...\n    end\n    ```\n\n* \u003Ca name=\"indent-multi-line-bool\">\u003C\u002Fa>Indent succeeding lines in multi-line\n    boolean expressions.\u003Csup>[[link](#indent-multi-line-bool)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    def is_eligible?(user)\n      Trebuchet.current.launch?(ProgramEligibilityHelper::PROGRAM_TREBUCHET_FLAG) &&\n      is_in_program?(user) &&\n      program_not_expired\n    end\n\n    # good\n    def is_eligible?(user)\n      Trebuchet.current.launch?(ProgramEligibilityHelper::PROGRAM_TREBUCHET_FLAG) &&\n        is_in_program?(user) &&\n        program_not_expired\n    end\n    ```\n\n### Inline\n\n* \u003Ca name=\"trailing-whitespace\">\u003C\u002Fa>Never leave trailing whitespace.\n    \u003Csup>[[link](#trailing-whitespace)]\u003C\u002Fsup>\n\n* \u003Ca name=\"space-before-comments\">\u003C\u002Fa>When making inline comments, include a\n    space between the end of the code and the start of your comment.\n    \u003Csup>[[link](#space-before-comments)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    result = func(a, b)# we might want to change b to c\n\n    # good\n    result = func(a, b) # we might want to change b to c\n    ```\n\n* \u003Ca name=\"spaces-operators\">\u003C\u002Fa>Use spaces around operators; after commas,\n    colons, and semicolons; and around `{` and before `}`.\n    \u003Csup>[[link](#spaces-operators)]\u003C\u002Fsup>\n\n    ```ruby\n    sum = 1 + 2\n    a, b = 1, 2\n    1 > 2 ? true : false; puts 'Hi'\n    [1, 2, 3].each { |e| puts e }\n    ```\n\n* \u003Ca name=\"no-space-before-commas\">\u003C\u002Fa>Never include a space before a comma.\n    \u003Csup>[[link](#no-space-before-commas)]\u003C\u002Fsup>\n\n    ```ruby\n    result = func(a, b)\n    ```\n\n* \u003Ca name=\"spaces-block-params\">\u003C\u002Fa>Do not include space inside block\n    parameter pipes. Include one space between parameters in a block.\n    Include one space outside block parameter pipes.\n    \u003Csup>[[link](#spaces-block-params)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    {}.each { | x,  y |puts x }\n\n    # good\n    {}.each { |x, y| puts x }\n    ```\n\n* \u003Ca name=\"no-space-after-!\">\u003C\u002Fa>Do not leave space between `!` and its\n    argument.\u003Csup>[[link](#no-space-after-!)]\u003C\u002Fsup>\n\n    ```ruby\n    !something\n    ```\n\n* \u003Ca name=\"no-spaces-braces\">\u003C\u002Fa>No spaces after `(`, `[` or before `]`, `)`.\n    \u003Csup>[[link](#no-spaces-braces)]\u003C\u002Fsup>\n\n    ```ruby\n    some(arg).other\n    [1, 2, 3].length\n    ```\n\n* \u003Ca name=\"no-spaces-string-interpolation\">\u003C\u002Fa>Omit whitespace when doing\n    string interpolation.\u003Csup>[[link](#no-spaces-string-interpolation)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    var = \"This #{ foobar } is interpolated.\"\n\n    # good\n    var = \"This #{foobar} is interpolated.\"\n    ```\n\n* \u003Ca name=\"no-spaces-range-literals\">\u003C\u002Fa>Don't use extra whitespace in range\n    literals.\u003Csup>[[link](#no-spaces-range-literals)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    (0 ... coll).each do |item|\n\n    # good\n    (0...coll).each do |item|\n    ```\n\n### Newlines\n\n* \u003Ca name=\"multiline-if-newline\">\u003C\u002Fa>Add a new line after `if` conditions spanning\n    multiple lines to help differentiate between the conditions and the body.\n    \u003Csup>[[link](#multiline-if-newline)]\u003C\u002Fsup>\n\n    ```ruby\n    if @reservation_alteration.checkin == @reservation.start_date &&\n       @reservation_alteration.checkout == (@reservation.start_date + @reservation.nights)\n\n      redirect_to_alteration @reservation_alteration\n    end\n    ```\n\n* \u003Ca name=\"newline-after-conditional\">\u003C\u002Fa>Add a new line after conditionals,\n    blocks, case statements, etc.\u003Csup>[[link](#newline-after-conditional)]\u003C\u002Fsup>\n\n    ```ruby\n    if robot.is_awesome?\n      send_robot_present\n    end\n\n    robot.add_trait(:human_like_intelligence)\n    ```\n\n* \u003Ca name=\"newline-different-indent\">\u003C\u002Fa>Don’t include newlines between areas\n    of different indentation (such as around class or module bodies).\n    \u003Csup>[[link](#newline-different-indent)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    class Foo\n\n      def bar\n        # body omitted\n      end\n\n    end\n\n    # good\n    class Foo\n      def bar\n        # body omitted\n      end\n    end\n    ```\n\n* \u003Ca name=\"newline-between-methods\">\u003C\u002Fa>Include one, but no more than one, new\n    line between methods.\u003Csup>[[link](#newline-between-methods)]\u003C\u002Fsup>\n\n    ```ruby\n    def a\n    end\n\n    def b\n    end\n    ```\n\n* \u003Ca name=\"method-def-empty-lines\">\u003C\u002Fa>Use a single empty line to break between\n    statements to break up methods into logical paragraphs internally.\n    \u003Csup>[[link](#method-def-empty-lines)]\u003C\u002Fsup>\n\n    ```ruby\n    def transformorize_car\n      car = manufacture(options)\n      t = transformer(robot, disguise)\n\n      car.after_market_mod!\n      t.transform(car)\n      car.assign_cool_name!\n\n      fleet.add(car)\n      car\n    end\n    ```\n\n* \u003Ca name=\"trailing-newline\">\u003C\u002Fa>End each file with a newline. Don't include\n    multiple newlines at the end of a file.\n    \u003Csup>[[link](#trailing-newline)]\u003C\u002Fsup>\n\n## Line Length\n\n* Keep each line of code to a readable length. Unless\n  you have a reason not to, keep lines to fewer than 100 characters.\n  ([rationale](.\u002Frationales.md#line-length))\u003Csup>\n  [[link](#line-length)]\u003C\u002Fsup>\n\n## Commenting\n\n> Though a pain to write, comments are absolutely vital to keeping our code\n> readable. The following rules describe what you should comment and where. But\n> remember: while comments are very important, the best code is\n> self-documenting. Giving sensible names to types and variables is much better\n> than using obscure names that you must then explain through comments.\n\n> When writing your comments, write for your audience: the next contributor who\n> will need to understand your code. Be generous — the next one may be you!\n\n&mdash;[Google C++ Style Guide][google-c++]\n\nPortions of this section borrow heavily from the Google\n[C++][google-c++-comments] and [Python][google-python-comments] style guides.\n\n### File\u002Fclass-level comments\n\nEvery class definition should have an accompanying comment that describes what\nit is for and how it should be used.\n\nA file that contains zero classes or more than one class should have a comment\nat the top describing its contents.\n\n```ruby\n# Automatic conversion of one locale to another where it is possible, like\n# American to British English.\nmodule Translation\n  # Class for converting between text between similar locales.\n  # Right now only conversion between American English -> British, Canadian,\n  # Australian, New Zealand variations is provided.\n  class PrimAndProper\n    def initialize\n      @converters = { :en => { :\"en-AU\" => AmericanToAustralian.new,\n                               :\"en-CA\" => AmericanToCanadian.new,\n                               :\"en-GB\" => AmericanToBritish.new,\n                               :\"en-NZ\" => AmericanToKiwi.new,\n                             } }\n    end\n\n  ...\n\n  # Applies transforms to American English that are common to\n  # variants of all other English colonies.\n  class AmericanToColonial\n    ...\n  end\n\n  # Converts American to British English.\n  # In addition to general Colonial English variations, changes \"apartment\"\n  # to \"flat\".\n  class AmericanToBritish \u003C AmericanToColonial\n    ...\n  end\n```\n\nAll files, including data and config files, should have file-level comments.\n\n```ruby\n# List of American-to-British spelling variants.\n#\n# This list is made with\n# lib\u002Ftasks\u002Flist_american_to_british_spelling_variants.rake.\n#\n# It contains words with general spelling variation patterns:\n#   [trave]led\u002Flled, [real]ize\u002Fise, [flav]or\u002Four, [cent]er\u002Fre, plus\n# and these extras:\n#   learned\u002Flearnt, practices\u002Fpractises, airplane\u002Faeroplane, ...\n\nsectarianizes: sectarianises\nneutralization: neutralisation\n...\n```\n\n### Function comments\n\nEvery function declaration should have comments immediately preceding it that\ndescribe what the function does and how to use it. These comments should be\ndescriptive (\"Opens the file\") rather than imperative (\"Open the file\"); the\ncomment describes the function, it does not tell the function what to do. In\ngeneral, these comments do not describe how the function performs its task.\nInstead, that should be left to comments interspersed in the function's code.\n\nEvery function should mention what the inputs and outputs are, unless it meets\nall of the following criteria:\n\n* not externally visible\n* very short\n* obvious\n\nYou may use whatever format you wish. In Ruby, two popular function\ndocumentation schemes are [TomDoc](http:\u002F\u002Ftomdoc.org\u002F) and\n[YARD](https:\u002F\u002Frubydoc.info\u002Fdocs\u002Fyard\u002Ffile\u002Fdocs\u002FGettingStarted.md). You can also\njust write things out concisely:\n\n```ruby\n# Returns the fallback locales for the_locale.\n# If opts[:exclude_default] is set, the default locale, which is otherwise\n# always the last one in the returned list, will be excluded.\n#\n# For example:\n#   fallbacks_for(:\"pt-BR\")\n#     => [:\"pt-BR\", :pt, :en]\n#   fallbacks_for(:\"pt-BR\", :exclude_default => true)\n#     => [:\"pt-BR\", :pt]\ndef fallbacks_for(the_locale, opts = {})\n  ...\nend\n```\n\n### Block and inline comments\n\nThe final place to have comments is in tricky parts of the code. If you're\ngoing to have to explain it at the next code review, you should comment it now.\nComplicated operations get a few lines of comments before the operations\ncommence. Non-obvious ones get comments at the end of the line.\n\n```ruby\ndef fallbacks_for(the_locale, opts = {})\n  # dup() to produce an array that we can mutate.\n  ret = @fallbacks[the_locale].dup\n\n  # We make two assumptions here:\n  # 1) There is only one default locale (that is, it has no less-specific\n  #    children).\n  # 2) The default locale is just a language. (Like :en, and not :\"en-US\".)\n  if opts[:exclude_default] &&\n      ret.last == default_locale &&\n      ret.last != language_from_locale(the_locale)\n    ret.pop\n  end\n\n  ret\nend\n```\n\nOn the other hand, never describe the code. Assume the person reading the code\nknows the language (though not what you're trying to do) better than you do.\n\n\u003Ca name=\"no-block-comments\">\u003C\u002Fa>Related: do not use block comments. They cannot\n  be preceded by whitespace and are not as easy to spot as regular comments.\n  \u003Csup>[[link](#no-block-comments)]\u003C\u002Fsup>\n\n  ```ruby\n  # bad\n  =begin\n  comment line\n  another comment line\n  =end\n\n  # good\n  # comment line\n  # another comment line\n  ```\n\n### Punctuation, spelling and grammar\n\nPay attention to punctuation, spelling, and grammar; it is easier to read\nwell-written comments than badly written ones.\n\nComments should be as readable as narrative text, with proper capitalization\nand punctuation. In many cases, complete sentences are more readable than\nsentence fragments. Shorter comments, such as comments at the end of a line of\ncode, can sometimes be less formal, but you should be consistent with your\nstyle.\n\nAlthough it can be frustrating to have a code reviewer point out that you are\nusing a comma when you should be using a semicolon, it is very important that\nsource code maintain a high level of clarity and readability. Proper\npunctuation, spelling, and grammar help with that goal.\n\n### TODO comments\n\nUse TODO comments for code that is temporary, a short-term solution, or\ngood-enough but not perfect.\n\nTODOs should include the string TODO in all caps, followed by the full name\nof the person who can best provide context about the problem referenced by the\nTODO, in parentheses. A colon is optional. A comment explaining what there is\nto do is required. The main purpose is to have a consistent TODO format that\ncan be searched to find the person who can provide more details upon request.\nA TODO is not a commitment that the person referenced will fix the problem.\nThus when you create a TODO, it is almost always your name that is given.\n\n```ruby\n  # bad\n  # TODO(RS): Use proper namespacing for this constant.\n\n  # bad\n  # TODO(drumm3rz4lyfe): Use proper namespacing for this constant.\n\n  # good\n  # TODO(Ringo Starr): Use proper namespacing for this constant.\n```\n\n### Commented-out code\n\n* \u003Ca name=\"commented-code\">\u003C\u002Fa>Never leave commented-out code in our codebase.\n    \u003Csup>[[link](#commented-code)]\u003C\u002Fsup>\n\n## Methods\n\n### Method definitions\n\n* \u003Ca name=\"method-def-parens\">\u003C\u002Fa>Use `def` with parentheses when there are\n    parameters. Omit the parentheses when the method doesn't accept any\n    parameters.\u003Csup>[[link](#method-def-parens)]\u003C\u002Fsup>\n\n     ```ruby\n     def some_method\n       # body omitted\n     end\n\n     def some_method_with_parameters(arg1, arg2)\n       # body omitted\n     end\n     ```\n\n* \u003Ca name=\"no-default-args\">\u003C\u002Fa>Do not use default positional arguments.\n    Use keyword arguments (if available - in Ruby 2.0 or later) or an options\n    hash instead.\u003Csup>[[link](#no-default-args)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    def obliterate(things, gently = true, except = [], at = Time.now)\n      ...\n    end\n\n    # good\n    def obliterate(things, gently: true, except: [], at: Time.now)\n      ...\n    end\n\n    # good\n    def obliterate(things, options = {})\n      options = {\n        :gently => true, # obliterate with soft-delete\n        :except => [], # skip obliterating these things\n        :at => Time.now, # don't obliterate them until later\n      }.merge(options)\n\n      ...\n    end\n    ```\n\n* \u003Ca name=\"no-single-line-methods\">\u003C\u002Fa>Avoid single-line methods. Although\n    they are somewhat popular in the wild, there are a few peculiarities about\n    their definition syntax that make their use undesirable.\n    \u003Csup>[[link](#no-single-line-methods)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    def too_much; something; something_else; end\n\n    # good\n    def some_method\n      # body\n    end\n    ```\n\n### Method calls\n\n**Use parentheses** for a method call:\n\n* \u003Ca name=\"returns-val-parens\">\u003C\u002Fa>If the method returns a value.\n    \u003Csup>[[link](#returns-val-parens)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    @current_user = User.find_by_id 1964192\n\n    # good\n    @current_user = User.find_by_id(1964192)\n    ```\n\n* \u003Ca name=\"first-arg-parens\">\u003C\u002Fa>If the first argument to the method uses\n    parentheses.\u003Csup>[[link](#first-arg-parens)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    put! (x + y) % len, value\n\n    # good\n    put!((x + y) % len, value)\n    ```\n\n* \u003Ca name=\"space-method-call\">\u003C\u002Fa>Never put a space between a method name and\n    the opening parenthesis.\u003Csup>[[link](#space-method-call)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    f (3 + 2) + 1\n\n    # good\n    f(3 + 2) + 1\n    ```\n\n* \u003Ca name=\"no-args-parens\">\u003C\u002Fa>**Omit parentheses** for a method call if the\n    method accepts no arguments.\u003Csup>[[link](#no-args-parens)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    nil?()\n\n    # good\n    nil?\n    ```\n\n* \u003Ca name=\"no-return-parens\">\u003C\u002Fa>If the method doesn't return a value (or we\n    don't care about the return), parentheses are optional. (Especially if the\n    arguments overflow to multiple lines, parentheses may add readability.)\n    \u003Csup>[[link](#no-return-parens)]\u003C\u002Fsup>\n\n    ```ruby\n    # okay\n    render(:partial => 'foo')\n\n    # okay\n    render :partial => 'foo'\n    ```\n\nIn either case:\n\n* \u003Ca name=\"options-no-braces\">\u003C\u002Fa>If a method accepts an options hash as the\n    last argument, do not use `{` `}` during invocation.\n    \u003Csup>[[link](#options-no-braces)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    get '\u002Fv1\u002Freservations', { :id => 54875 }\n\n    # good\n    get '\u002Fv1\u002Freservations', :id => 54875\n    ```\n\n## Conditional Expressions\n\n### Conditional keywords\n\n* \u003Ca name=\"multiline-if-then\">\u003C\u002Fa>Never use `then` for multi-line `if\u002Funless`.\n    \u003Csup>[[link](#multiline-if-then)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    if some_condition then\n      ...\n    end\n\n    # good\n    if some_condition\n      ...\n    end\n    ```\n\n* \u003Ca name=\"multiline-while-until\">\u003C\u002Fa>Never use `do` for multi-line `while` or\n    `until`.\u003Csup>[[link](#multiline-while-until)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    while x > 5 do\n      ...\n    end\n\n    until x > 5 do\n      ...\n    end\n\n    # good\n    while x > 5\n      ...\n    end\n\n    until x > 5\n      ...\n    end\n    ```\n\n* \u003Ca name=\"no-and-or\">\u003C\u002Fa>The `and`, `or`, and `not` keywords are banned. It's\n    just not worth it. Always use `&&`, `||`, and `!` instead.\n    \u003Csup>[[link](#no-and-or)]\u003C\u002Fsup>\n\n* \u003Ca name=\"only-simple-if-unless\">\u003C\u002Fa>Modifier `if\u002Funless` usage is okay when\n    the body is simple, the condition is simple, and the whole thing fits on\n    one line. Otherwise, avoid modifier `if\u002Funless`.\n    \u003Csup>[[link](#only-simple-if-unless)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad - this doesn't fit on one line\n    add_trebuchet_experiments_on_page(request_opts[:trebuchet_experiments_on_page]) if request_opts[:trebuchet_experiments_on_page] && !request_opts[:trebuchet_experiments_on_page].empty?\n\n    # okay\n    if request_opts[:trebuchet_experiments_on_page] &&\n         !request_opts[:trebuchet_experiments_on_page].empty?\n\n      add_trebuchet_experiments_on_page(request_opts[:trebuchet_experiments_on_page])\n    end\n\n    # bad - this is complex and deserves multiple lines and a comment\n    parts[i] = part.to_i(INTEGER_BASE) if !part.nil? && [0, 2, 3].include?(i)\n\n    # okay\n    return if reconciled?\n    ```\n\n* \u003Ca name=\"no-unless-with-else\">\u003C\u002Fa>Never use `unless` with `else`. Rewrite\n    these with the positive case first.\u003Csup>[[link](#no-unless-with-else)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    unless success?\n      puts 'failure'\n    else\n      puts 'success'\n    end\n\n    # good\n    if success?\n      puts 'success'\n    else\n      puts 'failure'\n    end\n    ```\n\n* \u003Ca name=\"unless-with-multiple-conditions\">\u003C\u002Fa>Avoid `unless` with multiple\n    conditions.\u003Csup>[[link](#unless-with-multiple-conditions)]\u003C\u002Fsup>\n\n    ```ruby\n      # bad\n      unless foo? && bar?\n        ...\n      end\n\n      # okay\n      if !(foo? && bar?)\n        ...\n      end\n    ```\n\n* \u003Ca name=\"unless-with-comparison-operator\">\u003C\u002Fa>Avoid `unless` with comparison operators if you can use `if` with an opposing comparison operator.\u003Csup>[[link](#unless-with-comparison-operator)]\u003C\u002Fsup>\n\n    ```ruby\n      # bad\n      unless x == 10\n        ...\n      end\n\n      # good\n      if x != 10\n        ...\n      end\n\n      # bad\n      unless x \u003C 10\n        ...\n      end\n\n      # good\n      if x >= 10\n        ...\n      end\n\n      # ok\n      unless x === 10\n        ...\n      end\n    ```\n\n* \u003Ca name=\"parens-around-conditions\">\u003C\u002Fa>Don't use parentheses around the\n    condition of an `if\u002Funless\u002Fwhile`.\n    \u003Csup>[[link](#parens-around-conditions)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    if (x > 10)\n      ...\n    end\n\n    # good\n    if x > 10\n      ...\n    end\n\n    ```\n\n### Ternary operator\n\n* \u003Ca name=\"avoid-complex-ternary\">\u003C\u002Fa>Avoid the ternary operator (`?:`) except\n    in cases where all expressions are extremely trivial. However, do use the\n    ternary operator(`?:`) over `if\u002Fthen\u002Felse\u002Fend` constructs for single line\n    conditionals.\u003Csup>[[link](#avoid-complex-ternary)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    result = if some_condition then something else something_else end\n\n    # good\n    result = some_condition ? something : something_else\n    ```\n\n* \u003Ca name=\"no-nested-ternaries\">\u003C\u002Fa>Use one expression per branch in a ternary\n    operator. This also means that ternary operators must not be nested. Prefer\n    `if\u002Felse` constructs in these cases.\u003Csup>[[link](#no-nested-ternaries)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    some_condition ? (nested_condition ? nested_something : nested_something_else) : something_else\n\n    # good\n    if some_condition\n      nested_condition ? nested_something : nested_something_else\n    else\n      something_else\n    end\n    ```\n\n* \u003Ca name=\"single-condition-ternary\">\u003C\u002Fa>Avoid multiple conditions in ternaries.\n    Ternaries are best used with single conditions.\n    \u003Csup>[[link](#single-condition-ternary)]\u003C\u002Fsup>\n\n* \u003Ca name=\"no-multiline-ternaries\">\u003C\u002Fa>Avoid multi-line `?:` (the ternary\n    operator), use `if\u002Fthen\u002Felse\u002Fend` instead.\n    \u003Csup>[[link](#no-multiline-ternaries)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    some_really_long_condition_that_might_make_you_want_to_split_lines ?\n      something : something_else\n\n    # good\n    if some_really_long_condition_that_might_make_you_want_to_split_lines\n      something\n    else\n      something_else\n    end\n    ```\n\n### Nested conditionals\n\n* \u003Ca name=\"no-nested-conditionals\">\u003C\u002Fa>\n  Avoid the use of nested conditionals for flow of control.\n  ([More on this][avoid-else-return-early].) \u003Csup>[[link](#no-nested-conditionals)]\u003C\u002Fsup>\n\n  Prefer a guard clause when you can assert invalid data. A guard clause\n  is a conditional statement at the top of a function that returns as soon\n  as it can.\n\n  The general principles boil down to:\n  * Return immediately once you know your function cannot do anything more.\n  * Reduce nesting and indentation in the code by returning early. This makes\n  the code easier to read and requires less mental bookkeeping on the part\n  of the reader to keep track of `else` branches.\n  * The core or most important flows should be the least indented.\n\n  ```ruby\n  # bad\n  def compute\n    server = find_server\n    if server\n      client = server.client\n      if client\n        request = client.make_request\n        if request\n           process_request(request)\n        end\n      end\n    end\n  end\n\n  # good\n  def compute\n    server = find_server\n    return unless server\n    client = server.client\n    return unless client\n    request = client.make_request\n    return unless request\n    process_request(request)\n  end\n  ```\n\n  Prefer `next` in loops instead of conditional blocks.\n\n  ```ruby\n  # bad\n  [0, 1, 2, 3].each do |item|\n    if item > 1\n      puts item\n    end\n  end\n\n  # good\n  [0, 1, 2, 3].each do |item|\n    next unless item > 1\n    puts item\n  end\n  ```\n\n  See also the section \"Guard Clause\", p68-70 in Beck, Kent.\n  *Implementation Patterns*. Upper Saddle River: Addison-Wesley, 2008, which\n  has inspired some of the content above.\n\n## Syntax\n\n* \u003Ca name=\"no-for\">\u003C\u002Fa>Never use `for`, unless you know exactly why. Most of the\n    time iterators should be used instead. `for` is implemented in terms of\n    `each` (so you're adding a level of indirection), but with a twist - `for`\n    doesn't introduce a new scope (unlike `each`) and variables defined in its\n    block will be visible outside it.\u003Csup>[[link](#no-for)]\u003C\u002Fsup>\n\n    ```ruby\n    arr = [1, 2, 3]\n\n    # bad\n    for elem in arr do\n      puts elem\n    end\n\n    # good\n    arr.each { |elem| puts elem }\n    ```\n\n* \u003Ca name=\"single-line-blocks\">\u003C\u002Fa>Prefer `{...}` over `do...end` for\n    single-line blocks.  Avoid using `{...}` for multi-line blocks (multiline\n    chaining is always ugly). Always use `do...end` for \"control flow\" and\n    \"method definitions\" (e.g. in Rakefiles and certain DSLs).  Avoid `do...end`\n    when chaining.\u003Csup>[[link](#single-line-blocks)]\u003C\u002Fsup>\n\n    ```ruby\n    names = [\"Bozhidar\", \"Steve\", \"Sarah\"]\n\n    # good\n    names.each { |name| puts name }\n\n    # bad\n    names.each do |name| puts name end\n\n    # good\n    names.each do |name|\n      puts name\n      puts 'yay!'\n    end\n\n    # bad\n    names.each { |name|\n      puts name\n      puts 'yay!'\n    }\n\n    # good\n    names.select { |name| name.start_with?(\"S\") }.map { |name| name.upcase }\n\n    # bad\n    names.select do |name|\n      name.start_with?(\"S\")\n    end.map { |name| name.upcase }\n    ```\n\n    Some will argue that multiline chaining would look okay with the use of\n    `{...}`, but they should ask themselves if this code is really readable and\n    whether the block's content can be extracted into nifty methods.\n\n* \u003Ca name=\"self-assignment\">\u003C\u002Fa>Use shorthand self assignment operators\n    whenever applicable.\u003Csup>[[link](#self-assignment)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    x = x + y\n    x = x * y\n    x = x**y\n    x = x \u002F y\n    x = x || y\n    x = x && y\n\n    # good\n    x += y\n    x *= y\n    x **= y\n    x \u002F= y\n    x ||= y\n    x &&= y\n    ```\n\n* \u003Ca name=\"semicolons\">\u003C\u002Fa>Avoid semicolons except for in single line class\n    definitions. When it is appropriate to use a semicolon, it should be\n    directly adjacent to the statement it terminates: there should be no\n    space before the semicolon.\u003Csup>[[link](#semicolons)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    puts 'foobar'; # superfluous semicolon\n    puts 'foo'; puts 'bar' # two expressions on the same line\n\n    # good\n    puts 'foobar'\n\n    puts 'foo'\n    puts 'bar'\n\n    puts 'foo', 'bar' # this applies to puts in particular\n    ```\n\n* \u003Ca name=\"colon-use\">\u003C\u002Fa>Use :: only to reference constants(this includes\n    classes and modules) and constructors (like Array() or Nokogiri::HTML()).\n    Do not use :: for regular method invocation.\u003Csup>[[link](#colon-use)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    SomeClass::some_method\n    some_object::some_method\n\n    # good\n    SomeClass.some_method\n    some_object.some_method\n    SomeModule::SomeClass::SOME_CONST\n    SomeModule::SomeClass()\n    ```\n\n* \u003Ca name=\"redundant-return\">\u003C\u002Fa>Avoid `return` where not required.\n    \u003Csup>[[link](#redundant-return)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    def some_method(some_arr)\n      return some_arr.size\n    end\n\n    # good\n    def some_method(some_arr)\n      some_arr.size\n    end\n    ```\n\n* \u003Ca name=\"assignment-in-conditionals\">\u003C\u002Fa>Don't use the return value of `=` in\n    conditionals\u003Csup>[[link](#assignment-in-conditionals)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad - shows intended use of assignment\n    if (v = array.grep(\u002Ffoo\u002F))\n      ...\n    end\n\n    # bad\n    if v = array.grep(\u002Ffoo\u002F)\n      ...\n    end\n\n    # good\n    v = array.grep(\u002Ffoo\u002F)\n    if v\n      ...\n    end\n\n    ```\n\n* \u003Ca name=\"double-pipe-for-uninit\">\u003C\u002Fa>Use `||=` freely to initialize variables.\n    \u003Csup>[[link](#double-pipe-for-uninit)]\u003C\u002Fsup>\n\n    ```ruby\n    # set name to Bozhidar, only if it's nil or false\n    name ||= 'Bozhidar'\n    ```\n\n* \u003Ca name=\"no-double-pipes-for-bools\">\u003C\u002Fa>Don't use `||=` to initialize boolean\n    variables. (Consider what would happen if the current value happened to be\n    `false`.)\u003Csup>[[link](#no-double-pipes-for-bools)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad - would set enabled to true even if it was false\n    enabled ||= true\n\n    # good\n    enabled = true if enabled.nil?\n    ```\n\n* \u003Ca name=\"lambda-calls\">\u003C\u002Fa>Use `.call` explicitly when calling lambdas.\n    \u003Csup>[[link](#lambda-calls)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    lambda.(x, y)\n\n    # good\n    lambda.call(x, y)\n    ```\n\n* \u003Ca name=\"no-cryptic-perl\">\u003C\u002Fa>Avoid using Perl-style special variables (like\n    `$0-9`, `$`, etc. ). They are quite cryptic and their use in anything but\n    one-liner scripts is discouraged. Prefer long form versions such as\n    `$PROGRAM_NAME`.\u003Csup>[[link](#no-cryptic-perl)]\u003C\u002Fsup>\n\n* \u003Ca name=\"single-action-blocks\">\u003C\u002Fa>When a method block takes only one\n    argument, and the body consists solely of reading an attribute or calling\n    one method with no arguments, use the `&:` shorthand.\n    \u003Csup>[[link](#single-action-blocks)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    bluths.map { |bluth| bluth.occupation }\n    bluths.select { |bluth| bluth.blue_self? }\n\n    # good\n    bluths.map(&:occupation)\n    bluths.select(&:blue_self?)\n    ```\n\n* \u003Ca name=\"redundant-self\">\u003C\u002Fa>Prefer `some_method` over `self.some_method` when\n    calling a method on the current instance.\u003Csup>[[link](#redundant-self)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    def end_date\n      self.start_date + self.nights\n    end\n\n    # good\n    def end_date\n      start_date + nights\n    end\n    ```\n\n    In the following three common cases, `self.` is required by the language\n    and is good to use:\n\n    1. When defining a class method: `def self.some_method`.\n    2. The *left hand side* when calling an assignment method, including assigning\n       an attribute when `self` is an ActiveRecord model: `self.guest = user`.\n    3. Referencing the current instance's class: `self.class`.\n\n* \u003Ca name=\"freeze-constants\">\u003C\u002Fa>When defining an object of any mutable\n    type meant to be a constant, make sure to call `freeze` on it. Common\n    examples are strings, arrays, and hashes.\n    ([More on this][ruby-freeze].)\u003Csup>[[link](#freeze-constants)]\u003C\u002Fsup>\n\n    The reason is that Ruby constants are actually mutable. Calling `freeze`\n    ensures they are not mutated and are therefore truly constant and\n    attempting to modify them will raise an exception. For strings, this allows\n    older versions of Ruby below 2.2 to intern them.\n\n    ```ruby\n    # bad\n    class Color\n      RED = 'red'\n      BLUE = 'blue'\n      GREEN = 'green'\n\n      ALL_COLORS = [\n        RED,\n        BLUE,\n        GREEN,\n      ]\n\n      COLOR_TO_RGB = {\n        RED => 0xFF0000,\n        BLUE => 0x0000FF,\n        GREEN => 0x00FF00,\n      }\n    end\n\n    # good\n    class Color\n      RED = 'red'.freeze\n      BLUE = 'blue'.freeze\n      GREEN = 'green'.freeze\n\n      ALL_COLORS = [\n        RED,\n        BLUE,\n        GREEN,\n      ].freeze\n\n      COLOR_TO_RGB = {\n        RED => 0xFF0000,\n        BLUE => 0x0000FF,\n        GREEN => 0x00FF00,\n      }.freeze\n    end\n    ```\n\n## Naming\n\n* \u003Ca name=\"snake-case\">\u003C\u002Fa>Use `snake_case` for methods and variables.\n    \u003Csup>[[link](#snake-case)]\u003C\u002Fsup>\n\n* \u003Ca name=\"camel-case\">\u003C\u002Fa>Use `CamelCase` for classes and modules. (Keep\n    acronyms like HTTP, RFC, XML uppercase.)\n    \u003Csup>[[link](#camel-case)]\u003C\u002Fsup>\n\n* \u003Ca name=\"screaming-snake-case\">\u003C\u002Fa>Use `SCREAMING_SNAKE_CASE` for other\n    constants.\u003Csup>[[link](#screaming-snake-case)]\u003C\u002Fsup>\n\n* \u003Ca name=\"predicate-method-names\">\u003C\u002Fa>The names of predicate methods (methods\n    that return a boolean value) should end in a question mark.\n    (i.e. `Array#empty?`).\u003Csup>[[link](#predicate-method-names)]\u003C\u002Fsup>\n\n* \u003Ca name=\"bang-methods\">\u003C\u002Fa>The names of potentially \"dangerous\" methods\n    (i.e. methods that modify `self` or the arguments, `exit!`, etc.) should\n    end with an exclamation mark. Bang methods should only exist if a non-bang\n    method exists. ([More on this][ruby-naming-bang].)\n    \u003Csup>[[link](#bang-methods)]\u003C\u002Fsup>\n\n* \u003Ca name=\"throwaway-variables\">\u003C\u002Fa>Name throwaway variables `_`.\n    \u003Csup>[[link](#throwaway-variables)]\u003C\u002Fsup>\n\n    ```ruby\n    version = '3.2.1'\n    major_version, minor_version, _ = version.split('.')\n    ```\n\n## Classes\n\n* \u003Ca name=\"avoid-class-variables\">\u003C\u002Fa>Avoid the usage of class (`@@`) variables\n    due to their \"nasty\" behavior in inheritance.\n    \u003Csup>[[link](#avoid-class-variables)]\u003C\u002Fsup>\n\n    ```ruby\n    class Parent\n      @@class_var = 'parent'\n\n      def self.print_class_var\n        puts @@class_var\n      end\n    end\n\n    class Child \u003C Parent\n      @@class_var = 'child'\n    end\n\n    Parent.print_class_var # => will print \"child\"\n    ```\n\n  As you can see all the classes in a class hierarchy actually share one\n  class variable. Class instance variables should usually be preferred\n  over class variables.\n\n* \u003Ca name=\"singleton-methods\">\u003C\u002Fa>Use `def self.method` to define singleton\n    methods. This makes the methods more resistant to refactoring changes.\n    \u003Csup>[[link](#singleton-methods)]\u003C\u002Fsup>\n\n    ```ruby\n    class TestClass\n      # bad\n      def TestClass.some_method\n        ...\n      end\n\n      # good\n      def self.some_other_method\n        ...\n      end\n    ```\n* \u003Ca name=\"no-class-self\">\u003C\u002Fa>Avoid `class \u003C\u003C self` except when necessary,\n    e.g. single accessors and aliased attributes.\n    \u003Csup>[[link](#no-class-self)]\u003C\u002Fsup>\n\n    ```ruby\n    class TestClass\n      # bad\n      class \u003C\u003C self\n        def first_method\n          ...\n        end\n\n        def second_method_etc\n          ...\n        end\n      end\n\n      # good\n      class \u003C\u003C self\n        attr_accessor :per_page\n        alias_method :nwo, :find_by_name_with_owner\n      end\n\n      def self.first_method\n        ...\n      end\n\n      def self.second_method_etc\n        ...\n      end\n    end\n    ```\n\n* \u003Ca name=\"access-modifiers\">\u003C\u002Fa>Indent the `public`, `protected`, and\n    `private` methods as much the method definitions they apply to. Leave one\n    blank line above and below them.\u003Csup>[[link](#access-modifiers)]\u003C\u002Fsup>\n\n    ```ruby\n    class SomeClass\n      def public_method\n        # ...\n      end\n\n      private\n\n      def private_method\n        # ...\n      end\n    end\n    ```\n\n## Exceptions\n\n* \u003Ca name=\"exception-flow-control\">\u003C\u002Fa>Don't use exceptions for flow of control.\n    \u003Csup>[[link](#exception-flow-control)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    begin\n      n \u002F d\n    rescue ZeroDivisionError\n      puts \"Cannot divide by 0!\"\n    end\n\n    # good\n    if d.zero?\n      puts \"Cannot divide by 0!\"\n    else\n      n \u002F d\n    end\n    ```\n\n* \u003Ca name=\"dont-rescue-exception\">\u003C\u002Fa>Avoid rescuing the `Exception` class.\n    \u003Csup>[[link](#dont-rescue-exception)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    begin\n      # an exception occurs here\n    rescue Exception\n      # exception handling\n    end\n\n    # good\n    begin\n      # an exception occurs here\n    rescue StandardError\n      # exception handling\n    end\n\n    # acceptable\n    begin\n      # an exception occurs here\n    rescue\n      # exception handling\n    end\n    ```\n\n* \u003Ca name=\"redundant-exception\">\u003C\u002Fa>Don't specify `RuntimeError` explicitly in\n    the two argument version of raise. Prefer error sub-classes for clarity and\n    explicit error creation.\u003Csup>[[link](#redundant-exception)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    raise RuntimeError, 'message'\n\n    # better - RuntimeError is implicit here\n    raise 'message'\n\n    # best\n    class MyExplicitError \u003C RuntimeError; end\n    raise MyExplicitError\n    ```\n\n\n* \u003Ca name=\"exception-class-messages\">\u003C\u002Fa>\n    Prefer supplying an exception class and a message as two separate arguments\n    to `raise`, instead of an exception instance.\n    \u003Csup>[[link](#exception-class-messages)]\u003C\u002Fsup>\n\n    ```Ruby\n    # bad\n    raise SomeException.new('message')\n    # Note that there is no way to do `raise SomeException.new('message'), backtrace`.\n\n    # good\n    raise SomeException, 'message'\n    # Consistent with `raise SomeException, 'message', backtrace`.\n    ```\n\n\n* \u003Ca name=\"rescue-as-modifier\">\u003C\u002Fa>Avoid using rescue in its modifier form.\n    \u003Csup>[[link](#rescue-as-modifier)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    read_file rescue handle_error($!)\n\n    # good\n    begin\n      read_file\n    rescue Errno:ENOENT => ex\n      handle_error(ex)\n    end\n    ```\n\n## Collections\n\n* \u003Ca name=\"map-over-collect\">\u003C\u002Fa>Prefer `map` over\n    `collect`.\u003Csup>[[link](#map-over-collect)]\u003C\u002Fsup>\n\n* \u003Ca name=\"detect-over-find\">\u003C\u002Fa>Prefer `detect` over `find`. The use of `find`\n    is ambiguous with regard to ActiveRecord's `find` method - `detect` makes\n    clear that you're working with a Ruby collection, not an AR object.\n    \u003Csup>[[link](#detect-over-find)]\u003C\u002Fsup>\n\n* \u003Ca name=\"reduce-over-inject\">\u003C\u002Fa>Prefer `reduce` over `inject`.\n    \u003Csup>[[link](#reduce-over-inject)]\u003C\u002Fsup>\n\n* \u003Ca name=\"size-over-count\">\u003C\u002Fa>Prefer `size` over either `length` or `count`\n    for performance reasons.\u003Csup>[[link](#size-over-count)]\u003C\u002Fsup>\n\n* \u003Ca name=\"empty-collection-literals\">\u003C\u002Fa>Prefer literal array and hash creation\n    notation unless you need to pass parameters to their constructors.\n    \u003Csup>[[link](#empty-collection-literals)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    arr = Array.new\n    hash = Hash.new\n\n    # good\n    arr = []\n    hash = {}\n\n    # good because constructor requires parameters\n    x = Hash.new { |h, k| h[k] = {} }\n    ```\n\n* \u003Ca name=\"array-join\">\u003C\u002Fa>Favor `Array#join` over `Array#*` for clarity.\n    \u003Csup>[[link](#array-join)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    %w(one two three) * ', '\n    # => 'one, two, three'\n\n    # good\n    %w(one two three).join(', ')\n    # => 'one, two, three'\n    ```\n\n* \u003Ca name=\"symbol-keys\">\u003C\u002Fa>Use symbols instead of strings as hash keys.\n    \u003Csup>[[link](#symbol-keys)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    hash = { 'one' => 1, 'two' => 2, 'three' => 3 }\n\n    # good\n    hash = { :one => 1, :two => 2, :three => 3 }\n    ```\n\n* \u003Ca name=\"symbol-literals\">\u003C\u002Fa>Relatedly, use plain symbols instead of string\n    symbols when possible.\u003Csup>[[link](#symbol-literals)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    :\"symbol\"\n\n    # good\n    :symbol\n    ```\n\n* \u003Ca name=\"deprecated-hash-methods\">\u003C\u002Fa>Use `Hash#key?` instead of\n    `Hash#has_key?` and `Hash#value?` instead of `Hash#has_value?`. According\n    to Matz, the longer forms are considered deprecated.\n    \u003Csup>[[link](#deprecated-hash-methods)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    hash.has_key?(:test)\n    hash.has_value?(value)\n\n    # good\n    hash.key?(:test)\n    hash.value?(value)\n    ```\n\n* \u003Ca name=\"multiline-hashes\">\u003C\u002Fa>Use multi-line hashes when it makes the code\n    more readable, and use trailing commas to ensure that parameter changes\n    don't cause extraneous diff lines when the logic has not otherwise changed.\n    \u003Csup>[[link](#multiline-hashes)]\u003C\u002Fsup>\n\n    ```ruby\n    hash = {\n      :protocol => 'https',\n      :only_path => false,\n      :controller => :users,\n      :action => :set_password,\n      :redirect => @redirect_url,\n      :secret => @secret,\n    }\n    ```\n\n* \u003Ca name=\"array-trailing-comma\">\u003C\u002Fa>Use a trailing comma in an `Array` that\n    spans more than 1 line\u003Csup>[[link](#array-trailing-comma)]\u003C\u002Fsup>\n\n    ```ruby\n    # good\n    array = [1, 2, 3]\n\n    # good\n    array = [\n      \"car\",\n      \"bear\",\n      \"plane\",\n      \"zoo\",\n    ]\n    ```\n\n## Strings\n\n* \u003Ca name=\"string-interpolation\">\u003C\u002Fa>Prefer string interpolation instead of\n    string concatenation:\u003Csup>[[link](#string-interpolation)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    email_with_name = user.name + ' \u003C' + user.email + '>'\n\n    # good\n    email_with_name = \"#{user.name} \u003C#{user.email}>\"\n    ```\n\n  Furthermore, keep in mind Ruby 1.9-style interpolation. Let's say you are\n  composing cache keys like this:\n\n    ```ruby\n    CACHE_KEY = '_store'\n\n    cache.write(@user.id + CACHE_KEY)\n    ```\n\n    Prefer string interpolation instead of string concatenation:\n\n    ```ruby\n    CACHE_KEY = '%d_store'\n\n    cache.write(CACHE_KEY % @user.id)\n    ```\n\n* \u003Ca name=\"string-concatenation\">\u003C\u002Fa>Avoid using `String#+` when you need to\n    construct large data chunks. Instead, use `String#\u003C\u003C`. Concatenation mutates\n    the string instance in-place  and is always faster than `String#+`, which\n    creates a bunch of new string objects.\u003Csup>[[link](#string-concatenation)]\u003C\u002Fsup>\n\n    ```ruby\n    # good and also fast\n    story = ''\n    story \u003C\u003C 'The Ugly Duckling'\n\n    paragraphs.each do |paragraph|\n      story \u003C\u003C paragraph\n    end\n    ```\n\n* \u003Ca name=\"multi-line-strings\">\u003C\u002Fa>Use `\\` at the end of the line instead of `+`\n    or `\u003C\u003C` to concatenate multi-line strings.\n    \u003Csup>[[link](#multi-line-strings)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    \"Some string is really long and \" +\n      \"spans multiple lines.\"\n\n    \"Some string is really long and \" \u003C\u003C\n      \"spans multiple lines.\"\n\n    # good\n    \"Some string is really long and \" \\\n      \"spans multiple lines.\"\n    ```\n\n## Regular Expressions\n\n* \u003Ca name=\"regex-named-groups\">\u003C\u002Fa>Avoid using `$1-9` as it can be hard to track\n    what they contain. Named groups can be used instead.\n    \u003Csup>[[link](#regex-named-groups)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    \u002F(regexp)\u002F =~ string\n    ...\n    process $1\n\n    # good\n    \u002F(?\u003Cmeaningful_var>regexp)\u002F =~ string\n    ...\n    process meaningful_var\n    ```\n\n* \u003Ca name=\"caret-and-dollar-regexp\">\u003C\u002Fa>Be careful with `^` and `$` as they\n    match start\u002Fend of line, not string endings.  If you want to match the whole\n    string use: `\\A` and `\\z`.\u003Csup>[[link](#caret-and-dollar-regexp)]\u003C\u002Fsup>\n\n    ```ruby\n    string = \"some injection\\nusername\"\n    string[\u002F^username$\u002F]   # matches\n    string[\u002F\\Ausername\\z\u002F] # don't match\n    ```\n\n* \u003Ca name=\"comment-regexes\">\u003C\u002Fa>Use `x` modifier for complex regexps. This makes\n    them more readable and you can add some useful comments. Just be careful as\n    spaces are ignored.\u003Csup>[[link](#comment-regexes)]\u003C\u002Fsup>\n\n    ```ruby\n    regexp = %r{\n      start         # some text\n      \\s            # white space char\n      (group)       # first group\n      (?:alt1|alt2) # some alternation\n      end\n    }x\n    ```\n\n## Percent Literals\n\n* \u003Ca name=\"percent-literal-delimiters\">\u003C\u002Fa>Prefer parentheses over curly\n    braces, brackets, or pipes when using `%`-literal delimiters for\n    consistency, and because the behavior of `%`-literals is closer to method\n    calls than the alternatives.\u003Csup>[[link](#percent-literal-delimiters)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    %w[date locale]\n    %w{date locale}\n    %w|date locale|\n\n    # good\n    %w(date locale)\n    ```\n\n* \u003Ca name=\"percent-w\">\u003C\u002Fa>Use `%w` freely.\u003Csup>[[link](#percent-w)]\u003C\u002Fsup>\n\n    ```ruby\n    STATES = %w(draft open closed)\n    ```\n\n* \u003Ca name=\"percent-parens\">\u003C\u002Fa>Use `%()` for single-line strings which require\n    both interpolation and embedded double-quotes. For multi-line strings,\n    prefer heredocs.\u003Csup>[[link](#percent-parens)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad - no interpolation needed\n    %(Welcome, Jane!)\n    # should be 'Welcome, Jane!'\n\n    # bad - no double-quotes\n    %(This is #{quality} style)\n    # should be \"This is #{quality} style\"\n\n    # bad - multiple lines\n    %(Welcome, Jane!\\nPlease enjoy your stay at #{location}\\nCheers!)\n    # should be a heredoc.\n\n    # good - requires interpolation, has quotes, single line\n    %(Welcome, #{name}!)\n    ```\n\n* \u003Ca name=\"percent-r\">\u003C\u002Fa>Use `%r` only for regular expressions matching *more\n    than* one '\u002F' character.\u003Csup>[[link](#percent-r)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    %r(\\s+)\n\n    # still bad\n    %r(^\u002F(.*)$)\n    # should be \u002F^\\\u002F(.*)$\u002F\n\n    # good\n    %r(^\u002Fblog\u002F2011\u002F(.*)$)\n    ```\n\n* \u003Ca name=\"percent-x\">\u003C\u002Fa>Avoid the use of %x unless you're going to invoke a\n    command with backquotes in it (which is rather unlikely).\n    \u003Csup>[[link](#percent-x)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    date = %x(date)\n\n    # good\n    date = `date`\n    echo = %x(echo `date`)\n    ```\n\n## Rails\n\n* \u003Ca name=\"next-line-return\">\u003C\u002Fa>When immediately returning after calling\n    `render` or `redirect_to`, put `return` on the next line, not the same line.\n    \u003Csup>[[link](#next-line-return)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    render :text => 'Howdy' and return\n\n    # good\n    render :text => 'Howdy'\n    return\n\n    # still bad\n    render :text => 'Howdy' and return if foo.present?\n\n    # good\n    if foo.present?\n      render :text => 'Howdy'\n      return\n    end\n    ```\n\n### Scopes\n* \u003Ca name=\"scope-lambda\">\u003C\u002Fa>When defining ActiveRecord model scopes, wrap the\n    relation in a `lambda`.  A naked relation forces a database connection to be\n    established at class load time (instance startup).\n    \u003Csup>[[link](#scope-lambda)]\u003C\u002Fsup>\n\n    ```ruby\n    # bad\n    scope :foo, where(:bar => 1)\n\n    # good\n    scope :foo, -> { where(:bar => 1) }\n    ```\n\n## Be Consistent\n\n> If you're editing code, take a few minutes to look at the code around you and\n> determine its style. If they use spaces around all their arithmetic\n> operators, you should too. If their comments have little boxes of hash marks\n> around them, make your comments have little boxes of hash marks around them\n> too.\n\n> The point of having style guidelines is to have a common vocabulary of coding\n> so people can concentrate on what you're saying rather than on how you're\n> saying it. We present global style rules here so people know the vocabulary,\n> but local style is also important. If code you add to a file looks\n> drastically different from the existing code around it, it throws readers out\n> of their rhythm when they go to read it. Avoid this.\n\n&mdash;[Google C++ Style Guide][google-c++]\n\n[airbnb-javascript]: https:\u002F\u002Fgithub.com\u002Fairbnb\u002Fjavascript\n[rubocop-guide]: https:\u002F\u002Fgithub.com\u002Frubocop-hq\u002Fruby-style-guide\n[github-ruby]: https:\u002F\u002Fgithub.com\u002Fstyleguide\u002Fruby\n[google-c++]: https:\u002F\u002Fgoogle.github.io\u002Fstyleguide\u002Fcppguide.html\n[google-c++-comments]: https:\u002F\u002Fgoogle.github.io\u002Fstyleguide\u002Fcppguide.html#Comments\n[google-python-comments]: https:\u002F\u002Fgoogle.github.io\u002Fstyleguide\u002Fpyguide.html#Comments\n[ruby-naming-bang]: https:\u002F\u002Fdavidablack.net\u002Fdablog.html#2007\u002F8\u002F15\u002Fbang-methods-or-danger-will-rubyist\n[ruby-freeze]: https:\u002F\u002Fblog.honeybadger.io\u002Fwhen-to-use-freeze-and-frozen-in-ruby\u002F\n[avoid-else-return-early]: http:\u002F\u002Fblog.timoxley.com\u002Fpost\u002F47041269194\u002Favoid-else-return-early\n\n## Translation\n\n  This style guide is also available in other languages:\n\n  - ![cn](https:\u002F\u002Fraw.githubusercontent.com\u002Fgosquared\u002Fflags\u002Fmaster\u002Fflags\u002Fflags\u002Fshiny\u002F24\u002FChina.png) **Chinese (Simplified)**: [1c7\u002Fruby-airbnb](https:\u002F\u002Fgithub.com\u002F1c7\u002Fruby-airbnb)\n","这是一个由Airbnb维护的Ruby代码风格指南。它详细规定了从空格使用、行长度到方法定义等多方面的编码规范，旨在帮助开发者编写更一致、更可读的Ruby代码。该风格指南受到GitHub和RuboCop风格指南的启发，并且涵盖了诸如缩进、注释、条件表达式、命名规则以及Rails框架特定建议等内容。适用于需要在团队中统一编码风格的场景，无论是大型项目还是小型应用，都能通过遵循这些规则来提高代码质量和协作效率。",2,"2026-06-11 03:14:28","top_language"]