Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created April 11, 2009 14:24
Show Gist options
  • Save brandon-beacher/93576 to your computer and use it in GitHub Desktop.
Save brandon-beacher/93576 to your computer and use it in GitHub Desktop.
class Array
def adjoin(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
separators = args
raise ArgumentError unless length == separators.length + 1
prefix = first.dup
separators.each_with_index do |separator, index|
suffix = at(index + 1)
prefix << separator if prefix.present? && suffix.present?
prefix << suffix if suffix.present?
end
prefix = options.delete :default_if_blank if prefix.blank?
prefix
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment