Closed bradgessler closed 2 months ago
I quite like this with the name grab
. @willcosgrove what are your thoughts?
I like grab
too. It is solving an interesting problem. I'm kind of surprised I haven't run into a need for it yet 🤔
In the example given, I would just use mix
and not have any need to grab out the class kwarg.
Oh, of course you can already use mix
for this. I’m trying to be very careful about what features we introduce in core, but I don’t think this represents a significant increase in complexity or maintenance burden. It’s the kind of thing that’s useful if you need it and disappears if you don’t, which I like.
Even though you can technically use mix
, with **mix(:class)
, I think something like this is quite a bit simpler when all you’re doing is passing along the class
.
def foo(class:)
div(class: [grab(class:), "some other classes here"])
end
The implementation also allows you to grab multiple values with multiple assignment, e.g.
a, b, c, d = grab(class:, end:, while:, if:)
Its common to want to intercept the
class
kwarg like this:Phlex could have a method that makes this possible like this:
Not sure if
keyword
is the right method name. Some possible method names are:Previous attempt at https://github.com/phlex-ruby/phlex/pull/717 broke the way
tokens
behaved and was less composable. I believe this approach solves both of those problems.