Created
July 6, 2009 19:52
-
-
Save seanstickle/141641 to your computer and use it in GitHub Desktop.
Overriding the array multiplication method to support J-style array multiplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
alias_method :old_times, :* | |
def *(multiplier) | |
if multiplier.class != Array | |
self.old_times multiplier | |
else | |
if self.size != multiplier.size | |
raise "length error" | |
else | |
self.zip(multiplier).map {|x,y| x * y} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment