Conversation
a09a8d4 to
d79f44f
Compare
d79f44f to
e08c827
Compare
| fields.each do |name, val| | ||
| params["fields[#{name}]"] = val | ||
| end if fields | ||
| params["page[count]"] = (count || 10) unless count_not_passed |
There was a problem hiding this comment.
This desugars to:
if not count_not_passed
params["page[count]"] = (count || 10)
endWhen this method is:
- Called with
countset to3, thencount_not_passed == false,count == 3. This setsparams["page[count]"]to3 || 10, which evaluates to3. - Called with
countset tonil, thencount_not_passed == false,count == nil. This setsparams["page[count]"]tonil || 10, which evaluates to10. - Called without
count, thencount_not_passed == true,count == nil. This doesn't setparams["page[count]"]at all.
It looks like the intent is to provide three choices?
- Use the
countspecified. - Use default
count. - Omit
count.
If this triple-choice is to stay, I recommend turning the rest of the optional arguments into keyword args. Depending on the minimum Ruby version supported, we could either use real Ruby keyword args, or simulate them with a hash, as is a long-time traditional in older versions of Ruby.
There was a problem hiding this comment.
Great catch and great explanation! Looking at the python lib I don't even think we need to provide a default. I will update the logic to:
- Use the count specified.
- Omit count.
|
Although this The instance-variant of |
Do you think it is worth creating a separate PR to address that? Also wondering if there is a ruby gem that we could want to use. |
|
Yes, the author of that snippet has created a separate Edit: Yes, this can be addressed in another PR. |
|
I assume all changes to |
Yep! (Thanks for the reminder 😉) |
3009ed2 to
ec467c7
Compare
Co-authored-by: Wil Lee <wlee@patreon.com>
Update Ruby lib to APIv2.
The generation code lives in https://github.com/Patreon/patreon_py/pull/18680
Note to reviewer
It should be easier to look at each commit individually.
Inspiration: Patreon/patreon-python#28