Description
What version of protobuf and what language are you using?
Version: 3.19.1
Language: Ruby (JRuby 9.3)
What operating system (Linux, Windows, ...) and version?
Darwin.
What did you do?
First, thanks a lot for reenabling jruby support 🙏
I have code which checks whether a certain field exists.I use the idiomatic .respond_to?
in CRuby. Things aren't working the same way in JRuby however.
What did you expect to see
I'd expect the check to work. To compare, here's how it works in CRuby (v3.0):
# given a Google::Protobuf::Duration message
message.respond_to?(:seconds) #=> true
# although the method isn't defined
message.methods - Object.instance_methods #=> [:to_f, :method_missing, :[], :[]=, :to_h, :to_json, :to_proto]
What did you see instead?
In Jruby, I don't get the same result for the respond_to?
call, even if I can call .seconds
.
message.respond_to?(:seconds) #=> false
message.seconds #=> 123
I suspect this happens because .seconds
gets sent to method_missing
, which then infers the value of the field; and the respective .respond_to_missing?
method isn't defined, which makes my example break.