From: Josh Cheek Date: 2010-10-12T22:13:52+09:00 Subject: Re: How to do this --001485f20c166d28cd04926b3faf Content-Type: text/plain; charset=ISO-8859-1 On Tue, Oct 12, 2010 at 8:02 AM, Damjan Rems wrote: > I don't know how to explain so I will just code: > > template = 'some text #{variable}' # single quotes for reason > variable = 'filled' > res = some_method(template) > > Here, res should have value 'some text filled'. > > Is there an easy way doing this in ruby. Hard way is of course parsing > and inserting text with my own method. > > by > TheR > > -- > Posted via http://www.ruby-forum.com/. > > Using ERB, here is a pretty straight forward cheatsheet/examples for you: http://github.com/JoshCheek/JoshsRubyKickstart/blob/master/cheatsheets/erb-embedded_ruby.rb require 'erb' def some_method(template) ERB.new( template , 0 , '>' ).result end template = 'some text <%= variable %>' variable = 'filled' res = some_method(template) res # => "some text filled" --001485f20c166d28cd04926b3faf--