sagax has quit [Read error: Connection reset by peer]
sagax has joined #jruby
razetime has quit [Ping timeout: 260 seconds]
razetime has joined #jruby
razetime has quit [Ping timeout: 252 seconds]
razetime has joined #jruby
razetime has quit [Ping timeout: 260 seconds]
razetime has joined #jruby
razetime_ has joined #jruby
razetime has quit [Ping timeout: 260 seconds]
sagax has quit [Ping timeout: 260 seconds]
razetime has joined #jruby
sagax has joined #jruby
razetime has quit [Ping timeout: 260 seconds]
razetime has joined #jruby
drbobbeaty_ has joined #jruby
drbobbeaty has quit [Ping timeout: 272 seconds]
razetime has quit [Ping timeout: 260 seconds]
razetime has joined #jruby
razetime has quit [Ping timeout: 260 seconds]
razetime_ has joined #jruby
genpaku has quit [Read error: Connection reset by peer]
genpaku has joined #jruby
<kalenp[m]>
Good morning, interop question: When calling from java to ruby, I know you can use an interface to bridge that direction, but how do you call a ruby method with kwargs? Does that java interface take a final argument of `Map<String, Object> kwargs`, is there something more idiomatic, or is that just not supported?
<enebo[m]>
kalenp: For 9.3.x and lower if it is a Map and last argument it will work...or should work
<enebo[m]>
For 9.4, you will need to Hash.ruby2keywords(map_thing) and I think or it should end up working
<enebo[m]>
err ruby2_keywords_hash. And also note this will dup the map_thing which makes me wonder if we will need to do something to make this lighter
<enebo[m]>
I am glad you brought this up since it will end up as a problem with keywords being special from 3.0+ Ruby behavior
<enebo[m]>
Until there is something lighter for 9.4 doing something like making a Ruby method which accepts non-kwargs but then **them into the signraute where you really use keywords will be a workaround
<enebo[m]>
This should fix the rails issue with zsuper and kwrest
<kalenp[m]>
* a non-kwargs java interface which
<kalenp[m]>
I eventually came up with a solution like your last one which I think I'll use (do it indirectly. a ruby class implementing a non-kwargs interface which calls the kwargs methods), but I was curious enough about how to do it directly that I wanted to hop on and see if I was missing something
<enebo[m]>
kalenp: for 9.3 I believe it should just work as last arg since there is not special kwargs checking happening
<enebo[m]>
9.4 will be more of an issue and I think we may need to add something since dup'ing a Map means converting everything in it
<kalenp[m]>
what is the type of the kwargs map? Map<String, Object>? Map<Symbol, RubyObject>?
<enebo[m]>
oh
<enebo[m]>
That is a good question. I missed your main question because I have been working on kwargs for 3.0 support :)
<enebo[m]>
I believe second half can be literally anything but first part I don't know. Let me try something. I guess for this to work key must be convertable to RubySymbol
<enebo[m]>
ok I thought maybe we magically did something here with Map but we don't. Then I tried working around it with to_sym in a wrapper and it doesn't. It will work with using RubySymbols as the keys but that is not very broad
<enebo[m]>
I feel like this should work and I am mildly perplexed it gives 0 for 1 here and not something saying no foo: provided
<enebo[m]>
In 9.4 I would expect that error since it is not really a kwarg
<kalenp[m]>
interesting that kwargs are a new distinct type and not just a hash. I guess I haven't been keeping up with ruby3 changes
<enebo[m]>
**h does change the error to String (not Symbol) in 9.3
<enebo[m]>
which technically is what I should have written
<enebo[m]>
Let me retry my hack
<enebo[m]>
So the Map if it is RubySymbol, Anything it will work but as String/RubyString it just does not know it is Java and we just extract based on something being the proper type
<enebo[m]>
I should rescind some statements above...I think using ** will make this work either way in 9.3 and 9.4 since it will be a rest kwarg but the original question of key type is a problem in both
<enebo[m]>
in Ruby 3+ kwargs are first class but ** handles this for 3+
<kalenp[m]>
I think for now I'll go with the 2-step process (interface with flat method calling kwargs method), but we (Looker) would be interested in a more idiomatic method eventually if that was on your radar. We're in the progress of moving more of our code from ruby to kotlin and that means more interop both directions as we call legacy code from new components.
<enebo[m]>
kalenp: feel free to give a use case in an issue and mark as enhancement
<enebo[m]>
It feels like **java_map is a place where we can do something but we cannot do that in a way where all things are impacted
<enebo[m]>
kalenp: conceivably in this example you could make RubySymbol directly as part of mapOf but you don't want all this extra code at all
<kalenp[m]>
it would be nice to not have to pull in jruby as a compilation dependency, but barring that, we could use a RubySymbol there. if we did that, do you expect it would work?
<enebo[m]>
I think so? but Map<RubySymbol in interface and not String
<enebo[m]>
It is not explicitly doing **map so it might still be the 1 for 0 arity error
<kalenp[m]>
from the java/kotlin side, how would you splat the kwargs?
<enebo[m]>
yeah how can we even specify that
<kalenp[m]>
"splat the kwargs", lol
<enebo[m]>
we have no calling convention for it in 9.3 anyways. In 9.4 since it is a tracked special thing Hash.ruby2_keywords_hash might be a possibility
<enebo[m]>
or something similar for java which can do the same thing that is done for Hash
<enebo[m]>
I think the mechanism for this on Java side could be we make an interface you can mark to say you want it to be kwargs hash maybe?
<enebo[m]>
That does mean whatever you pass in must implement it but I am not sure how we kwrest pass a param using Java syntax...marking with a Type seems like one way. Perhaps annotation is another?
<kalenp[m]>
🤷getting beyond my knowledge of jruby internals here
<enebo[m]>
kalenp: in this case though I think this is mostly just how do you specify something on the Java side
<enebo[m]>
Java specifically is the odd thing out here since it has no kwargs so how do we indicate something in Java (e.g. this param is an X)
<enebo[m]>
internally we would still need to go "oh this thing is X. Now how do we make that kwarg internally"
<enebo[m]>
At this point anything as last param is just an ordinary Map parameter so we treat it as arg n in an argument list
<kalenp[m]>
that makes sense. if I attach that gist to a bug, is that a good motivating example for you guys to track?
<enebo[m]>
kalenp: yeah. It is a good start. A pure-Java example would not be bad either but this shows the basic issue
<kalenp[m]>
looking again, I can streamline it even a bit more, since you don't care why we want to be calling the kwargs method, that's just how I got here
<kalenp[m]>
sure, I can try to translate the kotlin to java
<enebo[m]>
kalenp: cool.
<enebo[m]>
we are pretty heads down trying to get 9.4 out but this appears like it will continue to be a use case we will hit since more and more Ruby is using kwargs
<enebo[m]>
by end of month hopefully we have 9.4.0.0 out and we can look at some stuff like this
<kalenp[m]>
I've got a workaround for now, but thanks for the discussion. Good luck with 9.4! We're working on getting ourselves upgraded to the latest 9.3 right now, too.