Created
April 29, 2009 17:13
-
-
Save dreamcat4/103906 to your computer and use it in GitHub Desktop.
Ruby snippets
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
# 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