What is Ruby?
Ruby is −- A high-level programming language.
- Interpreted like Perl, Python, Tcl/TK.
- Object-oriented like Smalltalk, Eiffel, Ada, Java.
Why Ruby?
Ruby originated in Japan and now it is gaining popularity in US and Europe as well. The following factors contribute towards its popularity −- Easy to learn
- Open source (very liberal license)
- Rich libraries
- Very easy to extend
- Truly object-oriented
- Less coding with fewer bugs
- Helpful community
- Performance Issues − Although it rivals Perl and Python, it is still an interpreted language and we cannot compare it with high-level programming languages like C or C++.
- Threading model − Ruby does not use native threads. Ruby threads are simulated in the VM rather than running as native OS threads.
Sample Ruby Code
Here is a sample Ruby code to print "Hello Ruby"# The Hello Class class Hello def initialize( name ) @name = name.capitalize end def salute puts "Hello #{@name}!" end end # Create a new object h = Hello.new("Ruby") # Output "Hello Ruby!" h.saluteOutput − This will produce the following result −
Hello Ruby!
Embedded Ruby
Ruby provides a program called ERB (Embedded Ruby), written by Seki Masatoshi. ERB allows you to put Ruby codes inside an HTML file. ERB reads along, word for word, and then at a certain point, when it encounters a Ruby code embedded in the document, it starts executing the Ruby code.You need to know only two things to prepare an ERB document −
- If you want some Ruby code executed, enclose it between <% and %>.
- If you want the result of the code execution to be printed out, as a part of the output, enclose the code between <%= and %>.
<% page_title = "Demonstration of ERB" %> <% salutation = "Dear programmer," %> <html> <head> <title><%= page_title %></title> </head> <body> <p><%= salutation %></p> <p>This is an example of how ERB fills out a template.</p> </body> </html>
tp> erb erbdemo.rbThis will produce the following result −
<html> <head> <title>Demonstration of ERb</title> </head> <body> <p>Dear programmer,</p> <p>This is an example of how ERb fills out a template.</p> </body> </html>
What is Rails?
- An extremely productive web-application framework.
- Written in Ruby by David Heinemeier Hansson.
- You could develop a web application at least ten times faster with Rails than you could with a typical Java framework.
- An open source Ruby framework for developing database-backed web applications.
- Configure your code with Database Schema.
- No compilation phase required.
Full Stack Framework
- Includes everything needed to create a database-driven web application, using the Model-View-Controller pattern.
- Being a full-stack framework means all the layers are built to work seamlessly together with less code.
- Requires fewer lines of code than other frameworks.
Convention over Configuration
- Rails shuns configuration files in favor of conventions, reflection, and dynamic runtime extensions.
- Your application code and your running database already contain everything that Rails needs to know!
No comments:
Post a Comment