Skip to content

Commit

Permalink
Add guideline for constant definitions in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneius authored and bbatsov committed Sep 13, 2020
1 parent bb0e31e commit 801381a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,27 @@ class TestClass
end
----

=== Defining Constants within a Block [[no-constant-definition-in-block]]

Do not define constants within a block, since the block's scope does not isolate or namespace the constant in any way.

Define the constant outside of the block instead, or use a variable or method if defining the constant in the outer scope would be problematic.

[source,ruby]
----
# bad - FILES_TO_LINT is now defined globally
task :lint do
FILES_TO_LINT = Dir['lib/*.rb']
# ...
end
# good - files_to_lint is only defined inside the block
task :lint do
files_to_lint = Dir['lib/*.rb']
# ...
end
----

== Classes: Constructors

=== Factory Methods [[factory-methods]]
Expand Down

0 comments on commit 801381a

Please sign in to comment.