Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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