New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return an Enumerator for #each_key without a block #2
Return an Enumerator for #each_key without a block #2
Conversation
joeyates
commented
Dec 13, 2014
- Makes the implementation more conformant with MRI,
- I've made a Pull Request to MRI Ruby (test gdbm each_key called without a block ruby/ruby#783) adding a test for the same case,
- With Ruby >= 2 it would be etter to return a lazy enumerator.
* Makes the implementation more conformant with MRI
@@ -149,11 +149,17 @@ def self.each_pair(file) | |||
|
|||
#Iterates over each key in the _file_. | |||
def self.each_key(file) | |||
keys = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Any reason to not check block_given?
at the beginning and return self.keys.each
? Seems simpler.-
Edit: haha I don't know what I'm talking about...never mind.
…thout_block Return an Enumerator for #each_key without a block
Thanks, Joe! Are you actually using this library? I kind of assumed anyone who installed it was just confused... I'll push a new gem version. |
I hope I'm not confused... I'm using https://github.com/y10k/rims which depends on the MRI Ruby builtin. As I didn't have GDBM installed when I compiled Ruby, I had to install libgdbm-dev and then reinstall Ruby to use it. I'm sure I'm not the first to have to do this. If this gem became the replacement for the builtin an GDBM was removed from MRI core, it would be good - one less dependency. It might be worth proposing as much to the MRI maintainers. |
I worry some people think this is how you get gdbm because the gem is named "gdbm" - but you need the actual gdbm C library installed no matter what. |
I released version 1.3.0 of the gem. Please let me know if I can help with anything else! I'm just glad someone found this useful. |
Thanks. I'll try bugging the MRI maintainers about removing GDBM from the standard library. Who knows. |
I suspect an FFI-based library for GDBM would need to use Fiddle instead of relying on the FFI gem. |