Created
April 11, 2009 14:24
-
-
Save brandon-beacher/93576 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
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