Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jruby ArrayList multiple assignment
Current behavior:
$ irb
jruby-1.7.1 :001 > require 'java'
=> false
jruby-1.7.1 :002 > java_import 'java.util.ArrayList'
=> [Java::JavaUtil::ArrayList]
jruby-1.7.1 :003 > a = ArrayList.new
=> #<Java::JavaUtil::ArrayList:0x12910b0b>
jruby-1.7.1 :004 > a << 1 << 2
=> #<Java::JavaUtil::ArrayList:0x12910b0b>
jruby-1.7.1 :005 > b, c = a
=> [#<Java::JavaUtil::ArrayList:0x12910b0b>]
jruby-1.7.1 :006 > puts b
[1, 2]
=> nil
jruby-1.7.1 :007 > puts c
=> nil
Expected behavior:
jruby-1.7.1 :008 > class ArrayList
jruby-1.7.1 :009?> alias_method :to_ary, :to_a
jruby-1.7.1 :010?> end
=> Java::JavaUtil::ArrayList
jruby-1.7.1 :011 > a = ArrayList.new
=> #<Java::JavaUtil::ArrayList:0x10fa1b2d>
jruby-1.7.1 :012 > a << 1 << 2
=> #<Java::JavaUtil::ArrayList:0x10fa1b2d>
jruby-1.7.1 :013 > b, c = a
=> [1, 2]
jruby-1.7.1 :014 > puts b
1
=> nil
jruby-1.7.1 :015 > puts c
2
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.