Skip to content

Instantly share code, notes, and snippets.

@hoshinotsuyoshi
Created August 5, 2012 04:11
Show Gist options
  • Save hoshinotsuyoshi/3261620 to your computer and use it in GitHub Desktop.
Save hoshinotsuyoshi/3261620 to your computer and use it in GitHub Desktop.
配列同士の中身の掛け算(適当メモ)
class Array
def *(arr)
self.each_with_index.map{|e,i| e*arr[i] }
end
end
[3,4,5] * [6,-7,8] #=> [18,-28,40]
[[1,2],[3,4]] * [[-2,-3],[-3,-4]] #=> [[-2, -6], [-9, -16]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment