Skip to content

Commit 89151bd

Browse files
committed
Add examples for the three is the number thou shalt count rule
1 parent fa16ae0 commit 89151bd

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

README.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6304,6 +6304,33 @@ end
63046304

63056305
Avoid more than three levels of block nesting.
63066306

6307+
[source,ruby]
6308+
----
6309+
# bad
6310+
def process(items)
6311+
items.each do |item|
6312+
item.widgets.each do |widget|
6313+
widget.parts.each do |part|
6314+
part.update!
6315+
end
6316+
end
6317+
end
6318+
end
6319+
6320+
# good
6321+
def process(items)
6322+
items.each do |item|
6323+
process_widgets(item.widgets)
6324+
end
6325+
end
6326+
6327+
def process_widgets(widgets)
6328+
widgets.each do |widget|
6329+
widget.parts.each(&:update!)
6330+
end
6331+
end
6332+
----
6333+
63076334
=== Functional Code [[functional-code]]
63086335

63096336
Code in a functional way, avoiding mutation when that makes sense.

0 commit comments

Comments
 (0)