Created
November 18, 2009 06:05
-
-
Save dscataglini/237597 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def accumulate_js(key, path) | |
javascript_list[key] ||= [] | |
if path.class == Array || path.class == String | |
javascript_list[key] << path | |
javascript_list[key].flatten! | |
javascript_list[key].uniq! | |
else | |
raise ArgumentError | |
end | |
javascript_list | |
end | |
# by extracting the creation of @javascript_list we eliminated dependencies | |
# the previous code could also have had block variable scope side effects if run in Ruby < 1.9 | |
def include_accumulated_js(order_array, path_hash = javascript_list) | |
order_array.map do |key| | |
path_hash[key].map do |path| | |
javascript_include_tag(path) | |
end if path_hash[key] | |
end.join | |
end | |
private | |
def javascript_list | |
@javascript_list ||= {} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment