You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: README.adoc
+13
Original file line number
Diff line number
Diff line change
@@ -4394,6 +4394,19 @@ array.reverse.each { ... }
4394
4394
array.reverse_each { ... }
4395
4395
----
4396
4396
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
+
4397
4410
== Numbers
4398
4411
4399
4412
=== Underscores in Numerics [[underscores-in-numerics]]
0 commit comments