Skip to content

Instantly share code, notes, and snippets.

@dreamcat4
Created April 29, 2009 17:13
Show Gist options
  • Save dreamcat4/103906 to your computer and use it in GitHub Desktop.
Save dreamcat4/103906 to your computer and use it in GitHub Desktop.
Ruby snippets
# jsquared: given an array with contents like ["47", 12, "hello"],
# how do I prefix each element with a given string and then join
# the elements together with another string? for example, something like
# ["47", 12, "hello"].join_with_prefix("+", "**") should give me +47**+12**+hello
array = ["47", 12, "hello"]
result = String.new()
array.each do | s |
s.join_with_prefix("+", "**")
result.join("#{s}")
end
puts result
# delete leading whitespace (spaces/tabs/etc) from beginning of each line
# string.gsub(/^\s+/, "")
# delete BOTH leading and trailing whitespace from each line
# qbxml = string.gsub(/^\s+/, "").gsub(/\s+$/, $/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment