Robert Klemme
3/3/2009 5:30:00 PM
On 03.03.2009 15:58, Daniel Schoch wrote:
> Dominik Honnef wrote:
>> On [Tue, 03.03.2009 23:28], Daniel Schoch wrote:
>>> Hi,
>>>
>>> I have a string
>>> s = "$DIR/test/$FILE"
>>>
>>> Is there an easy way to expand this with the defined environment
>>> variables?
>> What do you mean by environment variables? The stuff in ENV, or the
>> constants like __FILE__ or simply global variables?
>
> I mean the stuff in ENV.
> SHELL:
> export DIR=x
> export FILE=y.z
>
> RUBY:
> I'd like to know the easiest way from
> s = "$DIR/test/$FILE"
> to
> s = "x/test/y.z"
Just wondering: is there anything that would prevent doing this:
s = "#{ENV["DIR"]/test/#{ENV["FILE"]}"
or even
s = File.join ENV["DIR"], "test", ENV["FILE"]
? In other words: is the format of your original string mandatory? If
not, I'd rather choose one of the other approaches.
Kind regards
robert