From: Ryan Leavengood Date: 2006-04-25T11:11:26+09:00 Subject: Re: Format of RUBYOPT On 4/24/06, Ryan Leavengood wrote: > > In other words, if I am to add rubygems as a new option while > preserving the older options, what would I do? Just add it with a > space prefix at the end of RUBYOPT? Responding to my own thread: Given that the above is true, I wrote Ruby script to work out the logic of this and here is the result: $already_defined = {} def add_to_rubyopt(var, rubyopt) a = rubyopt.split(' ') if not a.include?(var) a << var $already_defined[var] = nil else $already_defined[var] = true end a.join(' ') end def del_from_rubyopt(var, rubyopt) if not $already_defined[var] a = rubyopt.split(' ') a.delete(var) a.join(' ') else rubyopt end end require 'test/unit' class RubyOptTest < Test::Unit::TestCase def test_add_to_rubyopt var = 'rubygems' # Before and after tests [ ['', var], ['w', "w #{var}"], ['w v somethinglong', "w v somethinglong #{var}"] ].each do |before, after| assert_equal(after, add_to_rubyopt(var, before)) assert_equal(before, del_from_rubyopt(var, after)) end # Here nothing should be changed [var, "w #{var}", "w v #{var} somethinglong"].each do |s| assert_equal(s, add_to_rubyopt(var, s)) assert_equal(s, del_from_rubyopt(var, s)) end end end __END__ If the logic of the above seems wrong in any way, let me know. Now the trick is writing the above in the NSIS scripting language (it's practically like assembler compared to Ruby, grrr.) Ryan