- Ruby Basics
- Ruby - Home
- Ruby - Overview
- Ruby - Environment Setup
- Ruby - Syntax
- Ruby - Classes and Objects
- Ruby - Variables
- Ruby - Operators
- Ruby - Comments
- Ruby - IF...ELSE
- Ruby - Loops
- Ruby - Methods
- Ruby - Blocks
- Ruby - Modules
- Ruby - Strings
- Ruby - Arrays
- Ruby - Hashes
- Ruby - Date & Time
- Ruby - Ranges
- Ruby - Iterators
- Ruby - File I/O
- Ruby - Exceptions
- Ruby Advanced
- Ruby - Object Oriented
- Ruby - Regular Expressions
- Ruby - Database Access
- Ruby - Web Applications
- Ruby - Sending Email
- Ruby - Socket Programming
- Ruby - Ruby/XML, XSLT
- Ruby - Web Services
- Ruby - Tk Guide
- Ruby - Ruby/LDAP Tutorial
- Ruby - Multithreading
- Ruby - Built-in Functions
- Ruby - Predefined Variables
- Ruby - Predefined Constants
- Ruby - Associated Tools
- Ruby Useful Resources
- Ruby - Quick Guide
- Ruby - Useful Resources
- Ruby - Discussion
- Ruby - Ruby on Rails Tutorial
eRuby: Embeded Ruby
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, i.e., 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 complete details on eRuby, refer to eRuby Home.
ruby_associated_tools.htm
Advertisements
To Continue Learning Please Login
Login with Google