-
-
Save jcwilk/2a03147d2278dcc3283cbb2d466231f5 to your computer and use it in GitHub Desktop.
Example of how lazy enumerables break when you try to refine methods into them
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
module LockedEnumeration | |
refine Enumerator::Lazy do | |
def refined | |
if block_given? | |
each { |el| yield el } | |
else | |
enum_for(:refined) | |
end | |
end | |
end | |
end | |
using LockedEnumeration | |
Enumerator.new {}.lazy.refined # => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x0000555ee6935428>:each>>:refined> | |
Enumerator.new {}.lazy.refined.to_a # => undefined method `refined' for #<Enumerator::Lazy:0x0000555ee692fc08> (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment