Tutorials Point


  Ruby Basics
  Ruby Advanced
  Ruby Useful References
  Ruby Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

eRuby: Embeded Ruby


previous next AddThis Social Bookmark Button


eRuby stands for embedded Ruby. It's a tool that embeds fragments of Ruby code in other files such as HTML files similar to ASP, JSP and PHP.

eRuby allows Ruby code to be embedded within (delimited by) a pair of <% and %> delimiters. These embedded code blocks are then evaluated in-place ie. they are replaced by the result of their evaluation.

Syntax

Here is a syntax to write single line of eRuby code:

<% ruby code %>

They function like blocks in Ruby and are terminated by <% end %>.

<ul>
<% 3.times do %>

  <li>list item</li>

<% end %>
</ul>

All Ruby code after the # is ignored and treated as comments.

<%# ruby code %>

Example:

Here's a sample eRuby file:

This is sample eRuby file<br>
The current time here is <%=Time.now%>.
<%[1,2,3].each{|x|print x,"<br>\n"}%>

Here's the output from this sample file:

This is sample eRuby file<br>
The current time here is Wed Aug 29 18:54:45 JST 2001.
1
2
3

For a complete detail on eRuby, refer to eRuby Home.



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names