lib/epitools/permutations.rb in epitools-0.4.20 vs lib/epitools/permutations.rb in epitools-0.4.21
- old
+ new
@@ -1,31 +1,30 @@
require 'epitools/basetypes'
class Array
- alias_method :"*_without_permutations", :*
+ alias_method :multiply_without_permutations, :*
#
# Overloaded * operator.
#
# Original behaviour:
# array * number == <number> copies of array
# Extra behaviour:
# array * array = Cartesian product of the two arrays
#
def *(other)
- case other
- when Array
- # cross-product
- result = []
- (0...self.size).each do |a|
- (0...other.size).each do |b|
- result << [self[a], other[b]]
- end
+ if other.is_a? Array
+ # cross-product
+ result = []
+ (0...self.size).each do |a|
+ (0...other.size).each do |b|
+ result << [self[a], other[b]]
end
- result
- else
- send(:"*_without_permutations", other)
+ end
+ result
+ else
+ send(:multiply_without_permutations, other)
end
end
#
# Multiply the array by itself 'exponent'-times.