Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: JRuby 1.1.6
-
Fix Version/s: None
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:jruby 1.1.6 (ruby 1.8.6 patchlevel 114) (2008-12-17 rev 8388) [amd64-java]
-
Testcase included:yes
-
Number of attachments :
Description
Calculate the sum of all Array items:
Code (debug.rb):
arr = [34.0, 55.7, 84.6]
- method 1
total = 0.0; arr.each{|i| total += i}
puts total - method 2
total = arr.reduce(:+)
puts total
Output:
$ ruby debug.rb
174.3
174.3
$ jruby debug.rb
174.3
debug.rb:6: undefined method `reduce' for [34.0, 55.7, 84.6]:Array (NoMethodError)
There's no Array#reduce, #reduce is mixed in from Enumerable module and is supported by 1.9 and 1.8.7. JRuby doesn't support 1.8.7 but your case will work under JRuby in 1.9 mode.