Skip to content

Commit 440e01e

Browse files
nevanseregon
andcommitted
✅ Check Data.respond_to?(:define) for Data polyfill
Perhaps this will improve compatibility with JRuby and TruffleRuby? I tried to use `defined?(::Data.define)`, but that didn't work for some reason. 🤷 Co-authored-by: Benoit Daloze <[email protected]>
1 parent dc01372 commit 440e01e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/net/imap/data_lite.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
# SOFTWARE.
2626

27-
2827
module Net
2928
class IMAP
30-
data_or_object = RUBY_VERSION >= "3.2.0" ? ::Data : Object
29+
data_or_object =
30+
if RUBY_VERSION >= "3.2.0" && defined?(::Data) && ::Data.respond_to?(:define)
31+
::Data
32+
else
33+
Object
34+
end
3135
class DataLite < data_or_object
3236
def encode_with(coder) coder.map = to_h.transform_keys(&:to_s) end
3337
def init_with(coder) initialize(**coder.map.transform_keys(&:to_sym)) end
@@ -39,7 +43,7 @@ def init_with(coder) initialize(**coder.map.transform_keys(&:to_sym)) end
3943

4044
# :nocov:
4145
# Need to skip test coverage for the rest, because it isn't loaded by ruby 3.2+.
42-
return if RUBY_VERSION >= "3.2.0"
46+
return if RUBY_VERSION >= "3.2.0" && defined?(::Data) && ::Data.respond_to?(:define)
4347

4448
module Net
4549
class IMAP

0 commit comments

Comments
 (0)