On Sep 28, 10:20 am, SpringFlowers AutumnMoon <summercooln... / gmail.com> wrote: > in ERb, we need to write > > "the value is #{i}" > > and it is a bit more typing. can we have something like > > "the value is ##i" as a shorthand? and use #{ } when it involves more > complicated expressions? This feature has nothing to do with ERb; it's part of Ruby's string interpolation. For global and instance variables, you can already do this: "the value is #@i" If that's not enough, you'll have to make a case for an alternate syntax for local variable interpolation. > The other thing is that in PHP, they use "print" and "echo" to output > the HTML code. In Ruby, we always use <%= evaluated_value %> and it > might have a limit of always breaking up the code into <% %> and <%= > %> and <% %> > > <% results.each do |k,v| %> > <%= "#{k} #{v}" %> > <% end %> > > the people who like to use inject may be happy because they can have it > all in one line <%= results.inject {|k,v| k += ... %> > > but if we can have some way that the STDOUT is made into HTML code, like > > <%p results.each {|k,v| printf "... " %> 1) ERb has a local variable that you can append to if you like. C:\>qri ERB.new --------------------------------------------------------------- ERB::new ERB::new(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout') ------------------------------------------------------------------------ Constructs a new ERB object with the template specified in _str_. ... _eoutvar_ can be used to set the name of the variable ERB will build up its output in. This is useful when you need to run multiple ERB templates through the same binding and/or when you want to control where output ends up. Pass the name of the variable to be used inside a String. I find this useful when I want to control whitespace exactly and don't want to have to mess up my <%...%> delimiters to do so. For example: <%10.times{ _erbout << "\t\tHello World!\n" }%> 2) After prompting for this a couple years ago, people on the list helped create a patch to ERB to allow print and puts to concatenate to this string. See [1] below. This was followed by some discussion (again prompted by me) for a RCR to allow this to work. See [2] below. The discussion there is probably worth reading before we dive into this again. [1] http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/155537?155418-156804+split-mode-vertical [2] http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/152709?152641-153992+split-mode-vertical