Thursday, December 27

Ruby vs PHP - I

The more I speak on or about Ruby or Ruby on Rails, I got to face more and more questions.
I found list of few interesting videos comapring Ruby/RoR with existing languages/frameworks.
All the videos do reflect the points I have stressed with respect to Ruby:
1. Ruby easy to pickup
2. Ruby clean to code and easy to maintain.
3. Improves the coding standards and abilities of the developers.
4. Convention over Configuration.
5. Many built-in features and support.
6. DRY (Don't Repeat Yourself) principle

Do observe the above points while you go through the video presentations :)




Do observe the above points while you go through the video presentations :)



Do observe the above points while you go through the video presentations :)

Tuesday, December 18

Ruby on Rails simple examples & String Class

After the previous post, hope you successfully installed the ruby on to your machine and ready to speed up our tutorials.
Now let us see a simple math example, factorial function. How do we write a program that would calculate the factorial value of integer that we would pass.
Basically factorial is:
n! = 1                (when n==0)
   = n * (n-1)!       (otherwise)
  • The simple logic that we are aware is, factorial is nothing but a recursive function call.
It means we write a function and will be calling the same function within that. So this would look something like this:



If you notice here there are lot of points to carry with us,
  • You may notice the repeated occurrence of end.
  • You may also notice the lack of a return statement.
  • It is not needed because a ruby function returns the last thing that was evaluated in it. Though use of a return statement is permissible but it is not necessary here.
  • ARGV is an array which contains the command line arguments, and to_i converts a character string to an integer.
Experiments:
  1. What happens if I pass string as argument instead of integer?
  2. At the line “12”, replace the double quote with single quote and see what happens?
Download or View on Scribd

Ruby String Class:

A String object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String objects may be created using String::new or as literals.

Because of aliasing issues, users of strings should be aware of the methods that modify the contents of a String object.

· Methods with names ending in ``!’’ modify their receiver.

· Methods without a ``!’’ return a new String.

Ruby deals with strings as well as numerical data. A string may be double-quoted ("...") or single-quoted ('...').

· A double-quoted string allows character escapes by a leading backslash, and the evaluation of embedded expressions using #{}.

· A single-quoted string does not do this interpreting; what you see is what you get.

Examples:

If you had done the above mentioned experiments, it is easy to understand the above two points. The difference between the double and single quotes around a string. There are plenty of methods that ruby offers, they come very handy!

capitalize:

str.capitalize => new_str

This method turns the first letter of the string to upper case.

"ruby".capitalize    #=> "Ruby"

Methods with names ending in ``!’’ modify their receiver.

capitalize!:

str.capitalize! => str or nil
Modifies str by converting the first character to uppercase and the remainder to lowercase. Returns nil if no changes are made.

   a = "hello"
   a.capitalize!   #=> "Hello"
   a               #=> "Hello"
   a.capitalize!   #=> nil
Find more examples and other methods ruby supports.
Download or View on Scribd

Tuesday, December 11

Ruby on Rails Installing Ruby

Though you continue to work/experiment more on the online ruby editor, today we see how we would install the ruby on windows OS.
Recollect "Ruby is portable, which means can be installed on all OS's possible"

Ruby Installer for Windows. Download the executable ruby186-25.exe and double-click this file to install Ruby on your PC. (Accept all the defaults.)
Once you have installed your Ruby software, the System Environment Variable path is already set to point to the bin folder of Ruby. The installation also includes the First Edition of Programming Ruby book and the SciTE editor.

Just recollect what we had done and what's the Ruby Environment looks like.

Assuming that you installed Ruby in the folder c:/ruby, then the installation creates a number of sub-folders. See the list below.

c:/ruby/bin : Here the Ruby executables (including ruby and irb) have been installed.
c:/ruby/src : Here you get the Ruby source code.
c:/ruby/lib/ruby/gems : Here are the Ruby-Gems.
c:/ruby/lib/ruby/1.8 : Here you'll find program files written in Ruby. These files provide standard library facilities, which you can require from your own programs if you need the functionality they provide.
c:/ruby/lib/ruby/1.8/i386-mswin32 : Here you find architecture-specific extensions and libraries. These files are C-language extensions to Ruby; or, more precisely, they are the binary, runtime-loadable files generated from Ruby's C-language extension code, compiled into binary form as part of the Ruby installation process.
c:/ruby/lib/ruby/site_ruby : Here you store third-party extensions and libraries. This include your own code or some third party.
c:/ruby/samples/RubySrc-1.8.6/sample : Well, here you will find some sample Ruby programs.

From now we can also execute ruby snippets on the locally installed SciTE editor.
Open the Editor: start/Programs/Ruby-186-25/SciTE.
Press F8 to open an output window.

Create a folder named, say. rubyexamples on your C:\ and will keep all our programs in this folder. Let us repeat the our first program, that we had done yesterday online. That is

puts "Hello World!"

Now save the file as "hello.rb" under c:\rubyexamples folder. Note all ruby source files have the .rb extension.

Pressing on F5 would execute the program and outputs the string "Hello World!" on right side window.

  1. # hello.rb
  2. puts 'Hello'

Alternatively you can also type command "ruby hello.rb" to execute the hello.rb file.

Having installed the ruby on local system now repeat the yesterdays examples and practice more for better understanding.

Download the pdf version of Installing Ruby post.


Monday, December 10

Ruby on Rails Learning through examples

What ruby is used for?
Let us recollect the statement:
Ruby is "an interpreted scripting language for quick and easy object-oriented programming".
Ruby is used for many kind of applications be it writing automation scripts and run on your local pc's, or developing automation tools, or Website, or Blogs, Web Application or web based products and the list goes on...

We here pick up basics of Ruby just enough to get going with Rails and start developing simple websites and web applications.
All the things that we had said about ruby in earlier post What is Ruby? will be discussed in coming posts.
Learning through Examples:

Before even going for installing the ruby in your desktop, let us experiment on ruby with small examples and work/execute them here online.

This is our play ground:
This is called interactive ruby shell and we find ">>" similar to command/shell prompt. Now let's start with famous example of printing out "Hello World!" statement.
  1. type puts "Hello World!" >> puts "Hello World!"
  2. then click "Enter" button
  3. Now you would find the expected returned
  • >> puts "Hello World!"
  • Hello World!
    => nil
So puts is the ruby way of printing the things to console/prompt. The first line means to print the string within the quotes(i.e. Hello World!). Your would also find "=> nil" displayed in the next line of the Hello World! statement, puts always returns nil, which is Ruby’s absolutely-positively-nothing value.

Going on to the next example:
  • Ruby has simple syntax.
  • Ruby is dynamically typed.
  • Ruby needs no variable declarations.
  • Ruby operators are also methods.
Now I want to do simple math. Based on the above points,
to add two integers just type : 4+2
to subtract two integers just type : 4-2
to multiply two integers just type : 4*2
to divide two integers just type : 4/2
You can check out with other types also. Need not be of same type, since ruby is dynamic language at the run time they would be evaluated.
for example you type 2.0+3 and see for yourself.

Coming on to the variable declaration, ruby does not require the variable declarations. Let us the see this point also:
you type
>> a=5
=>5
>>b=2.0
=>2.0
>>c=a+b
=>7.0
As you see we have not declared the variables a,b,c and what type they hold. All these variables are evaluated at the run time and treated accordingly.
Ruby treat the operators(+,-,*,/,%...) as just like methods, which is conceptually derived from Smalltalk.

Download the pdf version of Learning Through Examples.
The pdf includes:
  • Useful links
  • Duck typing explained with example.
  • Examples with appropriate comments and explanation.
  • Ruby resources links.

Friday, December 7

Ruby on Rails - What is Ruby?

So, I am not just going to stop by providing the Ruby on Rails course structure.
I am here to start sharing the concepts what I understood about Ruby on Rails.
A gentle disclaimer, Nobody is perfect and in my attempt to become close to perfection I relied on world wide web to learn better and to understand the concepts clearly.

So let's start today with Introduction topic and discuss more on What is Ruby? If you are in hurry you can download What is Ruby?


Initially Some History about Ruby:

The language was created by Yukihiro "Matz" Matsumoto, who started working on Ruby on February 24, 1993, and released it to the public in 1995. "Ruby" was named as a gemstone because of a joke within Matsumoto's circle of friends alluding to Perl's name.

Some useful links that come handy when you are going through the course material:

Scripting Language : http://en.wikipedia.org/wiki/Scripting_language

Compiled Language : http://en.wikipedia.org/wiki/Compiled_language

Compilers : http://en.wikipedia.org/wiki/Compiler

Interpreters : http://en.wikipedia.org/wiki/Interpreter_%28computing%29

Object Oriented Programming : http://en.wikipedia.org/wiki/Object-oriented

Jargon to watch out:
Ruby, Interpreters, Compilers, Scripting Language, Compiled Language, Mixins, Operating System, Unix, Linux, Modules, Closures, Threads, Exceptions, Garbage Collectors,

Download the detailed Ruby on Rails Course contents.

Reach me @ tosumanthkrishnaATgmailDOTcom for more discussions.

Ruby is "an interpreted scripting language for quick and easy object-oriented programming".

Don’t be alarmed. We will take one by one:

Interpreted Scripting Language:

  • Ability to make operating system calls directly
  • Powerful string operations and regular expressions
  • Immediate feedback during development
  • Ruby programs can be executed from source code.(means to say need not be compiled)
Object Oriented Programming:
  • Everything is an object
  • Classes, inheritance, methods, etc.
  • Singleton methods
  • Mixin by module
  • Iterators and closures

Portable:

  • Runs on many different operating systems.
  • Windows 95 through XP, Linux, UNIX...

Simple and Fast:

  • Variable declarations are unnecessary (remember: everything is an object... including primitives)
  • Variables are not typed
  • Syntax is simple and consistent (like you are expressing something)
  • Automatic memory allocation and garbage collection

More...

  • Exception processing model
  • Dynamic loading
  • Threads


Download the detailed Ruby on Rails Course contents.

Download What is Ruby?

Reach me @ tosumanthkrishnaATgmailDOTcom for more discussions/tips/suggestions.

Wednesday, December 5

Ruby on Rails - Course structure

You find lot of materials, websites and many articles where you get information about Ruby and Ruby on Rails.
Well, do not get over loaded with the information. If anybody is serious about learning and practicing Ruby on Rails, can make use of the below course structure. This course structure, I had just jotted down to train freshers and friends whoever interested to know more about RoR.
Note: This structure is framed based on
  1. my experience in RoR.
  2. my previous session on RoR gathering.
If anybody is interested can contact me for more information.

Download Ruby on Rails course structure in pdf

Prerequisites for the RoR Course:
The course is structured keeping in view of less experienced/freshers in the industry. So considereable time is given for all introductory topics.
However, having knowledge/experience is an added advantage:

1. Exposure to any of the programming languages (c,c++,c#,java...)/Scripting languages(perl, php, smalltalk...).

2. Overview on how web application works.

3. Understanding of the necessity of Data models, Configuration Management.

4. Necessary tools/IDE's (Eclipse IDE, notepad...)

5. Good Analyzing skills.

6. Web Technologies (HTML, JavaScript, CSS, XML, )

Download Ruby on Rails course structure in pdf

COURSE CONTENT

Introduction

· What is Ruby?

· What is it used for?

· Where do I get and install Ruby?

· Core facilities, built-in library and standard library.

· Basic concepts - object orientation, regular expressions, arrays, hashes, etc.

Basic Ruby Language Elements

· Structure of statements and comments.

· Variables and constants.

· Operators. Assignments, calculations, etc. Integer, float and string formats.

· Single and double quotes, here documents, general strings.

Control Structures

· Blocks and the if statement.

· Writing conditions.

· Comparative, boolean and range operators.

· Conditionals - if, unless, case, etc. Loops - while, for in, until, etc. break, next, retry and redo. defined? and ternary operators.

Object Orientation: Individual Objects

· History - unstructured and structured code. Introduction to object oriented programming.

· Classes and methods.

· Static and nonstatic.

· Instances, constructors and destructors.

· Accessing members of a class.

· Loading and using classes.

· Direct access to variables.

· Encouraging class use.

Classes and Objects

· Objects, classes and methods.

· Constructors and attributes.

· Instance and class variables.

· Local and global variables.

· Class and object methods.

· Including files - load and require.

Collections (Arrays and Hashes) in Ruby

· What is a collection?

· Arrays and hashes.

· Constructing an array.

· Nesting arrays. Hash keys, iterators, etc.

More Classes and Objects

· Public, private and protected visibility.

· Singletons and defs.

· Inheritance mixins, and super.

· Destructors and garbage collection.

· Namespaces and modules.

· Hooks.

· Calling methods with code blocks.

· Looking inside objects - reflection.

Strings and Regular Expressions

· Anchors, literals, character groups and counts.

· Matching in Ruby.

· Modifiers i, o, x and m.

· Pattern matching variables.

Special Variables and Pseudo-Variables

· ARGV, $0 and friends - the command line.

· Other special variables from $: through $ to Other special variables from $: through $ to Other special variables from $: through $ to Other special variables from $: through $ to $<. lt;. lt;.

· Environment variables.

· Pseudo-variables.

· Reserved words in Ruby.

Exceptions.

· begin and end (and a mention of BEGIN and END).

· Raise and rescue.

· Throw and catch.


Download Ruby on Rails course structure in pdf

Ruby on the Web

· CGI and the Ruby Apache Module.

· Using cgi.rb; URL decoding, forms, sessions, cookies, etc.

· Embedding Ruby in HTML - the <% <%= and <%# tags.

Ruby GUIs, XML, MySQL Database Connectivity

· Using Ruby/DBI to connect to MySQL, Oracle, etc.

MVC ARCHITECTURE

· What is MVC Architecture?

· Importance of it?

· How it helps?

WebApplications

· What are WebApplications?

· Essentials of WebApplications?

· SDLC (Software Development Life Cycle)

· Database Architecture

· Configuration Management (concept & tools)

· Application/Web Servers


Rails Framework

· What is Ruby on Rails?

· MVC (Model, view, controller) design principles.

· Rails structures -

o WEBrick servers,

o URLs and embedded code.

o Directory structure.

o Database connections.

· Creating the application

o the database and tables.

· First application through Scaffolds.

· Validation and customising the display.

· Adding a new controller.

· Adding viewers and layouts.

· Active Records.

· Emailing and logging from within Rails.

Ajax

· What is AJAX?

Ajax on Rails

· How to implement AJAX on Rails framework?

· What is Protoype?

· What is Scriptaculous?

· Ajax Effects.

· Rich UI experience.

· Visual Effects.


HOW TO PUT ABOVE LEARN T CONCEPTS IN TO REAL TIME PROJECTS?

Download Ruby on Rails course structure in pdf
I am open to receive any enhancement tips and open for discussion on the course structure.(tosumanthkrishna AT gmail DOT com)

Ruby on Rails - The 10 Most Marketable Web Development Skills

After the brief talk on Ruby on Rails at Twincling society which was successful and satisfactory, I am keen on writing and talking more on Ruby on Rails development.
So one of the FAQ's I face most is
What is Ruby on Rails and what is the market for it?
I stumbled across one such article "The 10 Most Marketable Web Development Skills", where the list of web development skills provided.

Note:
  • This is not any comparison but just listing out current web developement skills that have market.
  • The order of the list is not based on any popularity.