Differences of Ruby and Perl

Ruby and Perl might have a number of similarities, but there are a number of features that makes them unique from each other.

In Ruby, you won’t encounter context-dependent rules like with Perl. The array literals go in brackets instead of parentheses. A variable isn’t the same as the object to which it refers in Ruby. Instead, it’s always seen just as a reference to an object. Ruby uses “def” instead of “sub”. Semicolons are not needed after each line. You end it up with ‘end’ instead. Diamond operators are not found in Ruby and fat commas are only used in hash literals.

Features of Ruby Programming

Ruby Programming is an object-oriented program. It has four levels of variable scope which are: global, class, instance, and local. It has exemption handling. There are iterators and closures that are based on passing blocks of code. Ruby is also a native, Perl-like regular expressions at language level. The program features an automatic garbage collecting, operator overloading and is highly portable. It is has cooperative multi-threading on all platforms using green threads. It has a large standard library and DLL/shared library dynamic loading on most platforms. Ruby supports dependency injection and object runtime alteration. Ruby currently lacks full support for Unicode, though it has partial support for UTF-8.

Yukihiro Matsumoto

Yukihiro Matsumoto, also known as Matz, is a Japanese software programmer and computer scientist born on April 14, 1965 in Osaka Prefecture in Western Honshi. He is best known all over the world as the father and creator of the Ruby Programming.

According to Japan Inc. He taught himself how to program until he graduated from high school. He took up Information Science from Tsukuba University and earned a degree. During his college days, he associated himself with research that has something to do with programming languages, compilers and the like. Yukihiro Matsumoto is married with four beautiful children and serves as a missionary in the church.

Similarities of Ruby and Perl

Perl is an awesome program and it creates awesome documents, but the only problem with Perl is its complexity.

Are you aware that Perl and Ruby has a lot of similarities? Read on and learn.

The parentheses are optional and the strings work just the same. There’s a package management system that is similar to CPAN (called Ruby Gems). You can see a lot of commonly used built-ins too. Both programs have Regexes that are built right. Both have embedded doc tools. In Ruby, it is called rdocs, and lastly, there is a general delimited string and regex quoting syntax similar to Perl’s.

The Philosophy of Ruby Programming

When Yukihiro Matsumoto created the Ruby Language, he aimed to make a design mainly for the programmers to be productive and at the same time enjoy by following the principles of a good interface design. He believed that the system design must first consider the human being over what the computer needs.

The principle of the least surprise (POLS) is the principle that Ruby Language follows. “Matz” (Matsumotol’s Nick) was quoted saying that his primary design goal was to make a language that the programmer will be required minimize work and confusion. Actually, he hasn’t applied the principle olf the least surprise to the design of Ruby, but the phase is somewhat related with the Ruby On Rails Programming

Ruby as a Programming Language

The Ruby language has been used for scripting jobs, but most often it is used as a general-purpose programming language. It can be used to write GUI applications and middle-tier server processes, as well as for managing server machines and databases. Ruby is also used for working with Web pages, interfacing to databases and producing dynamic content. Some clients are using it to write artificial intelligence and machine learning programs, and have been found to be useful as a means for exploratory mathematics and formatting book publications. It is a wonderful language for creating solutions in a variety of problem domains.

All About RubyOSA

Have you heard of RubyOSA? It is a free software that retrieves the scriptable definition of of a given application and populates a new Ruby namespace with classes, methods, constants, enumerations, and all other elements described by the terminology.

For better understanding, most Mac OS X applications are scriptable, and they define their scriptable interface in an XML format. RubyOSA parses this file and creates the Ruby API on the fly. This API will do the necessary AppleEvent work transparently for you (building and sending events).

RubyOSA can be an alternative to the RubyAEOSA project. The latter is more a set of Ruby bindings for the AppleEvent C API, while RubyOSA is a more high-level framework as the AppleEvent infrastructure is completely hidden.

Ruby as ApplyScript Replacement?

With the recent developments going on between OS X and Ruby, A lot of Ruby addicts are convinced that Ruby has the potential to be the de-facto OS scripting language of choice within the next few years. A lot of programmers find AppleScript secretive or hideous enough to avoid it wherever possible. There’s an article recently that compares an AppleScript code and it’s ruby alternative:

The AppleScript Code:

tell application “TextEdit”
get paragraph 1 of document “Read Me”
end tell

The Ruby Alternative
app(’TextEdit‘).documents[’Read Me‘].paragraphs[1].get

In reality, AppleScript is much more easier to understand, but the Ruby version is easier to remember in terms of its construction and as long as you’re familiar with Ruby syntax, you won’t get lost.

The Ruby on Rails Web Framework

Ruby on Rails is a framework for developing database-backed web applications using the Model-View-Control (MVC) pattern. Rails gives you a Ruby development environment, starting from the Ajax in the view, to the request and response in the controller, and to the domain model wrapping the database. Almost everyone from business startups to non-profits to enterprise organizations are using Rails. It is all about infrastructure, so it fits practically into any type of web application, be it software for collaboration, community, e-commerce, content management, statistics,or management. It works with a wide range of web servers and databases, just about any operating system.

Benefit of a Real Closure – What to Do with a Block Made into an Object

A closure can be reconverted into a block, so a closure can be used anywhere a block can be used. Closures are used to store the status of a block into an instance variable, once you convert a block into a closure, it is becomes an object that can by referenced by a variable. Just as they are used in other languages, closures can be passed around the object to customize behavior of methods. To pass some code to customize a method, just pass a block. But if you want to pass the same code to more than two methods — convert the block into a closure, and pass that closure object to multiple methods.

« Previous PageNext Page »

Copyright ©Basic Ruby On Rails Programming.