Skip to content

Instantly share code, notes, and snippets.

@igravious
Created October 10, 2011 13:35
Show Gist options
  • Save igravious/1275345 to your computer and use it in GitHub Desktop.
Save igravious/1275345 to your computer and use it in GitHub Desktop.
Recursive lazy evaluated URLs
require 'rubygems'
require 'camping'
require 'lazy'
class Endless
include Enumerable
def initialize
make_a_promise Lazy.promise &Proc.new
end
def make_a_promise(p)
@p = p
end
def get_promise
@p
end
def each
p = get_promise
a = []
while p
car, cdr = p
head_by_tail = car[1]
a << head_by_tail
yield head_by_tail
p = cdr.get_promise
end
a
end
def map
p = get_promise
a = []
while p
car, cdr = p
head_by_tail = car[1]
a << (yield head_by_tail)
p = cdr.get_promise
end
a
end
end
def endless_path(head, tail)
Endless.new { [[tail, head * tail], endless_path(head, tail+1)] }
end
Camping.goes :WowJustWow
module WowJustWow
end
module WowJustWow::Controllers
class Index
def get
"/"
end
end
class Dyn < R()
def self.urls
endless_path("/([^/]+)",1)
end
def get(first, *rest)
"#{first} #{rest}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment