```
def subsets(nums)
if nums.empty?
return [[]]
end
result = [[]]
nums.each_with_index do |num, index|
subsets(nums[index + 1...nums.length]).each do |subset|
result << [num] + subset
end
end
result
end
```