.sum doesn't work...is this due to the ruby version run in SU17?

.sum is not working in my sketchup:

[1, 2, 3].sum

> NoMethodError: undefined method `sum' for [1, 2, 3]:Array

> (eval):2062:in `<main>'

Is this due to the version of ruby that Sketchup 2017 runs?

Sketchup.version
> 17.2.2555
RUBY_VERSION
> 2.2.4

Yes. You can reference these documents specifically for Ruby 2.2.4

3 Likes

For cross version compatibility, you can instead use the reduce method that Array inherits from the Enumerable module.

sum = [1,2,3].reduce(:+)

… or within your plugin submodule …

  def sum(ary)
    ary.reduce(:+)
  end
2 Likes