From: Felipe Contreras <felipe.contreras@gmail.com>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v2 3/3] ruby: make db.config return an enumerator
Date: Tue, 29 Jun 2021 14:08:35 -0500 [thread overview]
Message-ID: <20210629190835.19381-4-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20210629190835.19381-1-felipe.contreras@gmail.com>
Currently db.config requires a block to work:
db.config { |k, v| puts '%s=%s' % [k, v] }
If you try to use it without a block you, get an error like:
in `config': no block given (LocalJumpError)
In Ruby most methods should return an Enumerator if no block is given,
like:
(1..10).each
=> #<Enumerator: ...>
This allows us to do:
db.config.to_a
db.config.to_h
db.config.each { |k, v| ... }
And of course what is already possible:
db.config { |k, v| ... }
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
bindings/ruby/database.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 571f7e24..926b0985 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -535,6 +535,8 @@ notmuch_rb_database_config (int argc, VALUE *argv, VALUE self)
notmuch_config_pairs_t *list;
const char *cprefix;
+ RETURN_ENUMERATOR(self, argc, argv);
+
Data_Get_Notmuch_Database (self, db);
rb_scan_args (argc, argv, "01", &prefix);
--
2.32.0
prev parent reply other threads:[~2021-06-29 19:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 19:08 [PATCH v2 0/3] ruby: add latest config API Felipe Contreras
2021-06-29 19:08 ` [PATCH v2 1/3] ruby: add new Database.open_with_config Felipe Contreras
2021-08-21 14:20 ` David Bremner
2021-06-29 19:08 ` [PATCH v2 2/3] ruby: add db.config Felipe Contreras
2021-06-29 19:08 ` Felipe Contreras [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210629190835.19381-4-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).