Find file that redefined Array#sum?

$definitions.sum{|definition| definition.instances.length }
=> ni1

$defintions is not defined on my machine.

Extensions should not be defining global variables.

And your extensions should avoid using them whenever possible.

Read the docs on Array#sum. The elements in the array must respond_to?(:+)
The Sketchup::ComponentDefinition class does not have a #+ method.

If you wish to sum all the counts of a collection of definitions, then first #map the collection to a new array of the integer lengths …

number =

For all used instances …

number =

EDIT: I read the docs wrong, sorry. The result of the block must respond to #+ method.

It works for me on a test model …

definitions = Sketchup.active_model.definitions
definitions.sum {|cdef| cdef.instances.length }
#=> 36

… but I’m using the Enumerable#sum that is mixed into the DefinitionList class.

You are trying to use Array#sum and it looks like it returns nil.

Extensions should not redefine base class methods !

Yes. I don’t know which developer overloaded this method. I just want to roast.
I think we should add new methods.

class Array
    def xxx_sum(&block)

Try running this …


If that doesn’t tell you the file, do a binary search. Switch off half of your extensions.
If it still doesn’t work, the culprit is those that are still loading, so cut those in half, etc.
If it does begin working, then the culprit is in the half that you switched off.
Continue switching off half of the possible culprits until you find the extension that did it.

Use refinements … File: refinements.rdoc [Ruby 2.7.2]

1 Like

@javalitterboy So what was the culprit ?

[“SketchUp/Plugins/pizi_dialog/plugins/pizitools_1.60.pizi/PiziTools/rb/windowizer4.rb”, 2]
Trying to notify the developer for processing.

1 Like