Skip to content

Instantly share code, notes, and snippets.

@bradgessler
Created August 20, 2010 20:04
Show Gist options
  • Save bradgessler/541032 to your computer and use it in GitHub Desktop.
Save bradgessler/541032 to your computer and use it in GitHub Desktop.
# This is half the implementation in the problem given to applicants...
class Tab
attr_accessor :url, :name
attr_reader :tabs
include ActionController::UrlWriter
def initialize(name=nil, url=nil, &block)
@name, @url = name, url
@tabs = []
instance_eval(&block) if block_given?
end
def active?(current_url)
current_url == url || tabs.any?{|c| c.active?(current_url)}
end
def tab(*args, &block)
@tabs << Tab.new(*args, &block)
end
def active(current_url)
@tabs.find{|t| t.active? current_url } || Tab.new
end
def each(&block)
@tabs.each(&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment