Skip to content

Instantly share code, notes, and snippets.

@kachick
Created July 28, 2013 14:46
Show Gist options
  • Save kachick/6098841 to your computer and use it in GitHub Desktop.
Save kachick/6098841 to your computer and use it in GitHub Desktop.
yieldへ2つ渡しててもブロック無しで呼んだらただのArrayにしかならないから、真偽使ってるなら気をつけたほうがいいかもね的なアレ
# https://github.com/rubinius/rubinius/blob/7866fbd80db7fe6e1de2627f5442c8abe6ce51ad/kernel/common/enumerable.rb#L113
# https://github.com/rubinius/rubinius/blob/7866fbd80db7fe6e1de2627f5442c8abe6ce51ad/kernel/common/enumerable.rb#L428
class Foo
def each
yield false
yield nil
end
end
p Foo.new.to_enum.any? #=> false
class Bar
def each
yield false
yield nil, false
end
end
p Bar.new.to_enum.any? #=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment