Skip to content

Instantly share code, notes, and snippets.

@darinwilson
Last active August 29, 2015 14:13
Show Gist options
  • Save darinwilson/bef5fd5bb4ce8651257a to your computer and use it in GitHub Desktop.
Save darinwilson/bef5fd5bb4ce8651257a to your computer and use it in GitHub Desktop.
RubyMotion Android: can't convert java.util.HashMap to Ruby Hash
# Update: there's an issue open in RubyMotion for this, so hopefully it will get resolved soon.
#
# http://hipbyte.myjetbrains.com/youtrack/issue/RM-725
#
# In the meantime, here's a workaround: https://gist.github.com/darinwilson/26c8b573a65d8bc4c64b
# if you create a Ruby Hash...
ruby_hash = { foo: "bar" }
# ...you can call Ruby methods...
ruby_hash.has_key?(:foo)
# ...and java.util.HashMap methods
ruby_hash.containsKey(:foo)
# but if you create a Java HashMap...
hash = Java::Util::HashMap.new
hash.put("foo", "bar")
# you can't call Ruby methods
hash["foo"] # <- raises com.rubymotion.NoMethodError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment