How can we achieve this in Ruby?
xs = [1,2,3]
x = 5
Then I need that sum = 1+2+3+1+2 = 9
You have the abstractions you need in the core, just wire them together: Enumerable#cycle,Enumerable#take and Enumerable#inject:
>> [1, 2, 3].cycle.take(5).inject(0, :+)
=> 9