I want to be able to do:
1.9.3-p448 :018 > string1 = string2 = "substring1"
=> "substring1"
1.9.3-p448 :019 > string1
=> "substring1"
1.9.3-p448 :020 > string2
=> "substring1"
1.9.3-p448 :021 > string1 += string2 += " substring2" # HERE
=> "substring1substring1 substring2"
1.9.3-p448 :022 > string1
=> "substring1substring1 substring2"
1.9.3-p448 :023 > string2
=> "substring1 substring2"
After the # HERE
line I would like both strings to contain "substring1 substring2"
. Is there a concise way of accomplishing this?
EDIT: The motivation for this is to build a string that will contain a plaintext password in it. I want to simultaneously build a loggable string that doesn't contain the password.
EDIT2: Using @Ajedi32's advice below, I now have this. Which is okay, but certainly not that pretty.
command = ""
public = ""
[command, public].each {|str| str << "command_name"}
[command, public].each {|str| str << " -a a"}
[command, public].each {|str| str << " -b b"}
[command, public].each {|str| str << " -c c"}
command << " -d d"
command << " -e e"
[command, public].each {|str| str << " -f f"}
command << " -g g"
[command, public].each {|str| str << " -h h"}
[command, public].each {|str| str << " -i i"}
puts command
=> command_name -a a -b b -c c -d d -e e -f f -g g -h h -i i
puts public
=> command_name -a a -b b -c c -f f -h h -i i
Is there a better way to accomplish this?