JRuby

Array#reduce is undefined

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor 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 :
    0

Description

Calculate the sum of all Array items:

Code (debug.rb):

arr = [34.0, 55.7, 84.6]

  1. method 1
    total = 0.0; arr.each{|i| total += i}
    puts total
  2. 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)

Activity

Hide
Marcin Mielzynski added a comment -

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.

Show
Marcin Mielzynski added a comment - 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.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: