Sha256: 95a5dc4819eaf05f53ec212e01ae67936bf3be9b541d9210d1c1697d73319718

Contents?: true

Size: 477 Bytes

Versions: 5

Compression:

Stored size: 477 Bytes

Contents

class Array

  class SizeMismatch < StandardError; end

  DOT_OPERATIONS =
  {
    :dotplus => :+,
    :dotminus => :-,
    :dotmul  => :*,
    :dotdiv  => :/,
    :dotmod  => :%,
    :dotpow  => :**,
  }

  DOT_OPERATIONS.each { |op, m| define_method(op) { |other| dotop(m, other) } }

protected

  def dotop(op, other)
    raise SizeMismatch unless self.size == other.size
    res = []
    self.each_index { |idx| res << (self[idx].send(op, other[idx])) }
    res
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-mext-0.13.0 lib/mext/array/dotop.rb
ruby-mext-0.12.1 lib/mext/array/dotop.rb
ruby-mext-0.12.0 lib/mext/array/dotop.rb
ruby-mext-0.11.1 lib/mext/array/dotop.rb
ruby-mext-0.11.0 lib/mext/array/dotop.rb