Skip to content

Commit d86f7f6

Browse files
ydahbbatsov
authored andcommitted
Add new "Object#yield_self" vs "Object#then" rule
Follow: rubocop/rubocop#10526 This PR adds "Object#yield_self" vs "Object#then" rule. Looking at how the method `Object#then` was created, method name `Object#yield_self` states intention, not behavior, so an alias method `Object#then` was created. Reference: https://bugs.ruby-lang.org/issues/14594
1 parent d647dd6 commit d86f7f6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.adoc

+13
Original file line numberDiff line numberDiff line change
@@ -4394,6 +4394,19 @@ array.reverse.each { ... }
43944394
array.reverse_each { ... }
43954395
----
43964396

4397+
=== `Object#yield_self` vs `Object#then` [[object-yield-self-vs-object-then]]
4398+
4399+
The method `Object#then` is preferred over the method `Object#yield_self`, since method name of `Object#yield_self` states the intention, not the behavior.
4400+
4401+
[source,ruby]
4402+
----
4403+
# bad
4404+
obj.yield_self { |x| x.do_something }
4405+
4406+
# good
4407+
obj.then { |x| x.do_something }
4408+
----
4409+
43974410
== Numbers
43984411

43994412
=== Underscores in Numerics [[underscores-in-numerics]]

0 commit comments

Comments
 (0)