Xxx.each {} callable only once: jirb feature or bug?

I can call xxx.each {} in IRB/Ruby as many times as I want, and I get
the same set of elements each time.

I just tried the same in JIRB and was surprised to discover that it
works as expected only on the first function call.

Is this a bug or a (perhaps Java-related) feature?

JIRB:

irb(main):011:0> ni = java.net.NetworkInterface.networkInterfaces
=> #<#Class:01xc24193:0x31688f
@java_object=#Java::JavaObject:0x1c794cc>

irb(main):012:0> ni.each {|ni| puts ni }
name:eth2 (eth2) index: 3 addresses:
/fe80:0:0:0:21f:3bfe:ec87:fa4d%3; # not my real info
/192.168.0.112; # not my real info
name:lo (lo) index: 1 addresses:
/0:0:0:0:0:0:0:1%1;
/127.0.0.1;
=> nil

irb(main):013:0> ni.each {|ni| puts ni }
NoMethodError: undefined method `each’ for
#Java::JavaNet::NetworkInterface:0x1f488f1

IRB:

irb(main):001:0> arr = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> arr.each {|val| puts val }
1
2
3
=> [1, 2, 3]
irb(main):003:0> arr.each {|val| puts val }
1
2
3
=> [1, 2, 3]

Just curious.

Thanks,

James

I just tried running the IRB code in JIRB, and it works as expected (in
normal Ruby). Perhaps there’s something special about
java.net.NetworkInterface.networkInterfaces?

IRB:

irb(main):001:0> arr = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> arr.each {|val| puts val }
1
2
3
=> [1, 2, 3]
irb(main):003:0> arr.each {|val| puts val }
1
2
3
=> [1, 2, 3]

I discovered more JRuby folks use a different forum. I asked the
question over there and received excellent answers:

http://www.nabble.com/xxx.each-{}-callable-only-once%3A-jirb-feature-or-bug--td25011557.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs