Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ruby is beautiful

Name: Anonymous 2009-08-26 15:25

class Cycle
    def cycle(*args)
      args[((@_cycles ||= Hash.new(-1))[args.hash] += 1) % args.size]
    end
end

More beautiful code plees?

Name: Anonymous 2012-01-27 0:41

is this what op is doing? or am I wrong?


function cycle(...)
  local index = 1
  local array = {...}
  local length = table.getn(array)
  return function()
    local value = array[index]
    index = index + 1
    if index > length then index = 1 end -- indecies starting at one kind of blows for this.
    return value
  end
end

for v in cycle('the', 'other', 'day', 'I', 'was', 'saying') do
  print(v)
end

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List