Created
March 18, 2024 13:52
-
-
Save kaspth/1b82c9e5c9a0a082dc5e96a8f51fe02a to your computer and use it in GitHub Desktop.
For multiple chains of mutating methods, most likely on Enumerables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tapper < BasicObject | |
def initialize(object) = @object = object | |
def method_missing(meth) | |
@object.tap(&meth) | |
self | |
end | |
end | |
class Object | |
def tapped(&) = Tapper.new(self).then { _1.instance_exec(_1, &) } | |
end | |
[].tapped { uniq!.reverse! } # For multiple chains of mutating methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment