相关疑难解决方法(0)

笛卡尔积红宝石

class CartesianProduct
include Enumerable
# your code here
end
#Examples of use
c = CartesianProduct.new([:a,:b], [4,5])
c.each { |elt| puts elt.inspect }
# [:a, 4]
# [:a, 5]
# [:b, 4]
# [:b, 5]
c = CartesianProduct.new([:a,:b], [])
c.each { |elt| puts elt.inspect }
# (nothing printed since Cartesian product
# of anything with an empty collection is empty)
Run Code Online (Sandbox Code Playgroud)

我是红宝石的新手.我理解如何定义笛卡儿积的实例方法,但我对此毫无头绪.我应该如何构造类对象以满足要求.

ruby ruby-on-rails

6
推荐指数
3
解决办法
7944
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1