Skip to content

Instantly share code, notes, and snippets.

@seanstickle
Created July 6, 2009 19:52
Show Gist options
  • Save seanstickle/141641 to your computer and use it in GitHub Desktop.
Save seanstickle/141641 to your computer and use it in GitHub Desktop.
Overriding the array multiplication method to support J-style array multiplication
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