Skip to content

Instantly share code, notes, and snippets.

@dscataglini
Created November 18, 2009 06:05
Show Gist options
  • Save dscataglini/237597 to your computer and use it in GitHub Desktop.
Save dscataglini/237597 to your computer and use it in GitHub Desktop.
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