On 12/13/06, benjohn / fysh.org <benjohn / fysh.org> wrote:
[snip]
> cf = CodeFragment.new
> cf.code_fragment = "sin(x+y)"
> puts cf.output_substitution({'x'=>1, 'y'=>2})
>
> should give "sin(1+2)"
[snip]


prompt> cat a.rb
s = "sin(x+y)"
h = {
        'x' => '1',
        'y' => '2',
}
h.each do |pattern, replacement|
  r = Regexp.new('\b' + Regexp.escape(pattern) + '\b')
        s.gsub!(r) { replacement }
end
p s

prompt> ruby a.rb
"sin(1+2)"



-- 
Simon Strandgaard
http://opcoders.com/