HEMANT SONKER'S BLOG

Sunday, December 2, 2007

Names in Ruby......

1. Names - Ruby names are used to refer to constants, variables, methods, classes, and modules. The first character of a name helps Ruby to distinguish its intended use. Certain names, are reserved words and should not be used as variable, method, class, or module name. Lowercase letter means the characters ''a'' though ''z'', as well as ''_'', the underscore. Uppercase letter means ''A'' though ''Z,'' and digit means ''0'' through ''9.'' A name is an uppercase letter, lowercase letter, or an underscore, followed by Name characters: This is any combination of upper- and lowercase letters, underscore and digits.

2. Variables - Variables in Ruby can contain data of any type. You can use variables in your Ruby programs without any declarations. Variable name itself denotes its scope (local, global, instance, etc.).

2.1. A local variable name consists of a lowercase letter followed by name characters (sunil, _z, hit_and_run).

2.2. An instance variable name starts with an ''at'' sign (''@'') followed by an upper- or lowercase letter, optionally followed by name characters (@sign, @_, @Counter).

2.3. A class variable name starts with two ''at'' signs (''@@'') followed by an upper- or lowercase letter, optionally followed by name characters (@@sign, @@_, @@Counter).

2.4. A constant name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. By convention, constant variables are normally spelled using uppercase letters and underscores throughout (module MyMath, PI=3.1416, class MyPune).

2.5. Global variables start with a dollar sign (''$'') followed by name characters. A global variable name can be formed using ''$-'' followed by any single character ($counter, $COUNTER, $-x).


3. Method names should begin with a lowercase letter. ''?'' and ''!'' are the only weird characters allowed as method name suffixes

Basic terms in Ruby....

• Class: A class is a definition of a concept in an object-oriented language such as
Ruby. We created classes called Pet, Dog, Cat, Snake, and Person. Classes can inherit
features from other classes, but still have unique features of their own.

• Object: An object is a single instance of a class (or, as can be the case, an instance of
a class itself). An object of class Person is a single person. An object of class Dog is a
single dog. Think of objects as real-life objects. A class is the classification, whereas
an object is the actual object or “thing” itself.

• Object orientation: Object orientation is the approach of using classes and objects
to model real-world concepts in a programming language, such as Ruby.

• Variable: In Ruby, a variable is a placeholder for a single object, which may be a
number, string, list, or an instance of a class that you have defined, such as, in this
chapter, a Pet.

• Method: A method represents a set of code (containing multiple commands and
statements) within a class and/or an object. For example, our Dog class objects had
a bark method that printed “Woof!” to the screen. Methods can also be directly
linked to classes, as with fred = Person.new, where new is a method that creates a
new object based upon the Person class. Methods can also accept data—known as
arguments or parameters—included in parentheses after the method name, as
with puts("Test").

• Arguments/parameters: The data passed to methods in parentheses (or, as in some
cases, following the method name without parentheses, as in puts "Test").

• Kernel: Some methods don’t require a class name to be usable, such as puts. These
are usually built-in, common methods that don’t have an obvious connection to
any classes. Many of these methods are included in Ruby’s Kernel module, a module
that provides functions that work from anywhere within Ruby code without
being explicitly referred to.

Ruby Is English for Computers

Computers can understand languages, though in a rather different fashion to how most
people do. Being logical devices that cannot understand subtlety or ambiguity, languages
such as English and French aren’t appealing to computers. Computers require languages
with logical structures and a well-defined syntax so that there’s a logical clarity in what
you’re telling the computer to do.
Clarity is required because almost everything you relay to the computer while programming
is an instruction (or command). Instructions are the basic building blocks of
all programs, and for the computer to perform (or execute) them properly, the programmer’s
intentions must be clear and precise. Many hundreds of these instructions are tied
together into programs that perform certain tasks, which means there’s little room for
error.
You also need to consider that other programmers might need to maintain computer
programs you’ve written. This won’t be the case if you’re just programming for fun, but it’s
important that your programs are easy to understand, so you can understand them when
you come back to them later on.

*this thing is gathered from one book named Apress begining ruby form ovice to professional

Ruby---a programming language

Ruby is a cross-platform interpreted language, which has many features in common with other 'scripting' languages such as Perl and Python.

It has been desgined on the concept of "Principle of Least Surprise"
Yukihiro Matsumoto, commonly known as ‘Matz’ created the Ruby language in 1993.

If you are already familiar with object oriented programming, Ruby should quickly become second nature. If you've struggled with learning object-oriented programming or are not familiar with it, Ruby should make more sense to you than other object-oriented languages because Ruby's methods are consistently named, concise, and generally act the way you expect.

Ruby differs from most other programming languages not only by syntax, but by culture, grammar,and customs.

The Ruby on Rails Web framework is a system for developing Web applications
that uses Ruby as its base language, and it powers hundreds of large Web sites.
Ruby is also used as a generic language from the command prompt, much like Perl.

Installing Ruby

Windows users have access to an excellent “one-click installer,” which
installs Ruby, a horde of extensions, a source code editor, and various documentation, in
“one click.” Ruby on Windows is as reliable and useful as it is on other operating systems,
and Windows makes a good environment for developing Ruby programs.

To get up and running as quickly as possible, follow these steps:
1. Open a Web browser and go to http://www.ruby-lang.org/en/downloads/.
2. Scroll down to “Ruby on Windows,” about halfway down the page.
3. In the “Ruby on Windows” section, you’ll see a few links for different versions of
Ruby you can download for Windows. Ideally you want to download the file at the link that’s highest in the list that’s referred to as a “One-Click Installer.” At the time of writing, this is version 1.8.5.
4. Click the link you found in step 3 and save it to your desktop.
5. Once download has completed, look on your desktop for the Ruby EXE file you just downloaded, and double-click it to load the installer.
6. If Windows gives you a “Security Error” box, click the “Run” button to give your
approval.
7. A typical installation program appears with some instructions. On the initial
screen, click “Next.”
8. Work your way through the installation screens. Leave the boxes checked to install
the text editors SciTE , and the Ruby package manager RubyGems. Unless you have a specific reason not to, let the installation program install Ruby in its default location of c:\ruby and its default program group.
9. Installation takes place when you see a stream of filenames flying up your screen.
Wait several minutes for the installation process to complete and enjoy the view.
There are a lot of files to install!
10. Installation is complete when the installation program says “Installation Complete”
and the “Next” button is clickable. Click the “Next” button, then click
“Finish” to exit the installation program.
If Ruby installed correctly, congratulations! Go to the “Start” menu and then the “Programs”
or “All Programs” menu. There should be a Ruby program group that contains
icons for SciTE, an uninstaller, and other bits and pieces.
To test that your
Ruby installation works correctly, you need to load the program listed as
“fxri – Interactive Ruby Help & Console,” so click this entry and wait for the program to
load.If fxri started properly, then Ruby is installed correctly.

Congratulations! Lastly, you need to be familiar with running Ruby and its associated utilities from the command prompt, so go to the “Start” menu, then “Run,” and type cmd into the box and click “OK”.

What is Open source??

Open source is a development method for software that harnesses the power of distributed peer review and transparency of process

If you’ve used Linux or downloaded certain types of software, you might be familiar with
the term “open source.”
Simply, open source means that the source code to an application
or library is made available publicly for other people to look at and use. There might
be restrictions on what people can do with the code (generally via a license), but it’s publicly
viewable.
Open source software needs an open source license—in contrast to, say, Microsoft Windows, whose source code isn’treadily available.

Software products such as the popular Apache Web server and the
MySQL database system are also available under varying open source licenses and are
routinely improved by unpaid coders.
The open source community is one of sharing knowledge freely and collaborating to
improve the systems and services that most of us use. Although proprietary software will
always have its place, open source is rapidly becoming the de facto way to develop programming
languages, libraries, and other non-application types of software.

Although many developers don’t necessarily open source the code to their
applications, they’ll often release the tools and code tricks to the community so that they
can benefit from the peer review and popularity that results.

Releasing your code as open source isn’t necessarily a bad business decision. It could
actually improve the quality of your code and tools, and make you much better known in
the industry.