Sha256: a9c8b2e5be156be99554b4f6dbf8c26c6c162b0bca5f287a260591c4036d5cfb

Contents?: true

Size: 730 Bytes

Versions: 4

Compression:

Stored size: 730 Bytes

Contents

module GMath3D
  class Util
    def self.check_arg_type(type, instance)
      unless(instance.kind_of?(type))
        raise(ArgumentError::new("type mismatch: #{instance.class} for #{type}"))
      end
    end
    
    def self.raise_argurment_error(instance)
      raise(ArgumentError::new("type mismatch: #{instance.class}"))
    end
  end
end

class Array
public
  def sum
    s, n = self.sum_with_number
    return s
  end
  def avg
    s, n = self.sum_with_number
    return s / n
  end

  def sum_with_number
    return nil, 0 if(self.size <= 0)
    s = nil
    n = 0
    self.each do |v|
      next if v.nil?
      if(s==nil)
        s = v
      else
        s += v
      end
      n += 1
    end
    return s, n
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gmath3D-0.2.2 lib/util.rb
gmath3D-0.2.1 lib/util.rb
gmath3D-0.2.0 lib/util.rb
gmath3D-0.1.1 lib/util.rb