Introducing Ruby
by James Thompson on Jul 18, 2009
- 1,492 views
Basic introduction to the history and uses of the Ruby programming lanaguage.
Basic introduction to the history and uses of the Ruby programming lanaguage.
http://github.com/jwthompson2/barcamp-nola-2009/
Accessibility
Categories
Tags
More...Upload Details
Uploaded via SlideShare as Apple Keynote
Usage Rights
Statistics
- Favorites
- 2
- Downloads
- 33
- Comments
- 0
- Embed Views
- Views on SlideShare
- 1,489
- Total Views
- 1,492


* Inspired by Perl, Eiffel, Ada, Lisp and Smalltalk.
* Its creator stated his goal was to "make Ruby natural, not simple."
Ruby is a very powerful language that is also very flexible. It is pervasively
object-oriented. It is a general purpose language, so it is useful in the same
places that Perl, PHP, etc. would be used.
release in Japan in 1995.
It saw its first English announcement in 1998 and
was followed by the publication of the Programming Ruby book in 2000 by Dave
Thomas and Andy Hunt.
The second edition of Programming Ruby, known as the
"Pickaxe Book" was released in 2004.
projects have made the switch to supporting 1.9. The community is tracking the
progress of this transition with relation to Gems as isitruby19.com
Beyond the "official" interpreter, usually referred to as "MRI," there are a
number of projects to develop alternative interpreters for various reasons and
to met various needs.
* Enterprise: Ruby 1.8 with better memory handling and other performance optimizations
* JRuby: Ruby on top of the JVM, fastest 1.8 implementation around.
* MacRuby: Ruby on top of Apple's Objective-C runtime.
* IronRuby: Ruby on top of the .NET DLR.
* Rubinius: Ruby developed with a tight C++ main interpreter and most of the rest of the language developed the Ruby subset understood by the main interpreter.
environment since many of the best and most useful Ruby Gems use C extensions
which are a pain to get working outside of a unix environment. There is the
one-click installer as well, but it is badly outdated, and the straight binary
releases from ruby-lang.org.
For Linux you can use your favorite package manager to install ruby, irb and
rdoc to get the whole base system. Some distros are starting to make 1.9
available but it usually has a suffix on all the commands which make them
more cumbersome.
For OS X if you have Leopard you already have Ruby available but if you use
MacPorts you can get the latest version and even 1.9 with no suffix. Mac users
also have access to the MacRuby project which is very promising and should
eventually make OS X an even better platform for Rubyists.
If you don't want to install Ruby you can play with an online interactive
environment at tryruby.hobix.com.
its documentation and different ways of using it.
"Ruby Way."
You are free to ignore these conventions if you like, but don't expect much
love from your fellow Rubyists. And you can expect a nasty warning from the
interpreter if you fiddle with what it expects of a constant, although you are
actually free to change a constant.
Module and Class names are actually constants which is why some consider it acceptable to use camel case for constants as well.
object.
With the exception of reserved keywords everything is an object in Ruby. This
allows for really interesting programming techniques in terms of chaining
method invocation and even manipulation of parameters.
Object is the parent of all classes.
Duck typing is the pattern Ruby follows where behavior is closely coupled to type.
strings which have the same character sequences are not the same. They have
different object ids and occupy separate places in memory. Some have described
symbols as immutable strings but this is really an oversimplification.
Used with hashes for keys and as pseudo-constants.
There is a lot more to symbols and whole blogs have focused on uses for
symbols so go Google Ruby symbols if you want to learn more.
available to you. Instance variables are unique to a particular instance of an
object while class variables are unique to all instances of a given class.
strings, as well as HEREDOC style strings and alternative encapsulated
strings. Strings also support interpolation of variables as well.
Escaped new lines are optional when using certain ruby methods. Most of the
time you don't need to be explicit with new lines, Ruby uses them where you
would expect automatically.
It supports decimal and scientific notation as well as hex and octal.
Ruby the last expression within a method is returned as the result of the
method by default. So explicit returns are not needed. You can do an explicit
return however.
inheritance, although there is an inheritance hierarchy at work in Ruby.
Inheritance is also pretty straightforward to achieve.
constructor for a class just define a method called initialize.
for the class, if defined they are usually tied to an instance variable.
much the same ends as multiple inheritance would provide but without the
confusion.
examples in irb is that I didn't redefine the entire class every time I did
something new. One of the most useful and potentially troublesome features of
Ruby is the open nature of classes and modules. You can just open them up and
add to them. Heck, there are even ways to remove methods and the like. Here's
an example of a modification to the way numbers work in Ruby.
You can add and redefine methods on any class or module very easily in Ruby.
Again, this is a very powerful but also dangerous capability.
That last one is a fun way to work with collections like arrays or hashes.
we've already discussed but here's a quick rundown of the standard ones,
including some we didn't talk about.
basically pieces of code that you can pass as arguments to method calls. We
saw a basic block with control structures.
You can think of blocks like anonymous methods that are able to capture the
context they are called in. Procs are essentially blocks that have been stored
in a variable. This allows a the Proc to be more reusable than a block and
allows the developer to avoid repetition.
Ruby also provides lambdas which are similar to Procs but check the number of
variables passed to them. For more on these three special structures in Ruby
you can Google them and learn all the different ways they can be used.
the de facto standard for distributing reusable Ruby code. Lots of libraries,
and most Ruby applications are distributed as Gems.
You can get RubyGems either by default with Ruby 1.9 or downloaded from
rubygems.org. But lets look at how you use RubyGems a little bit. Many Linux distros also have it available as a package.
definitely a productive community. The numbers for Github may give a slightly
exaggerated impression since many of the gems hosted with them are duplicates
of gems distributed through Rubyforge or are unstable development packages.
However, it is clear that Ruby is a healthy community of users sharing their
work with one another.