Created
August 20, 2010 20:04
-
-
Save bradgessler/541032 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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