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