lib/class_extensions.rb in rspreadsheet-0.2.3 vs lib/class_extensions.rb in rspreadsheet-0.2.4

- old
+ new

@@ -1,5 +1,7 @@ +# @private + class LibXML::XML::Node def elements result = [] each_element { |e| result << e } return result @@ -31,7 +33,17 @@ return nil end def equals?(node2) #TODO redefine == with this self.simplification_of?(node2) and node2.simplification_of?(self) + end +end + +class Array + def sum(identity = 0, &block) + if block_given? + map(&block).sum(identity) + else + inject { |sum, element| sum + element } || identity + end end end \ No newline at end of file