Provides a quick reference to the Ruby language, including language elements and many important API functions for quick look-up. Ruby is an easy-to-learn, dynamic, object-oriented programming language with dynamic typing and automatic memory management. While object-oriented at heart, it provides facilities for procedural and functional programming as well as extensive support for introspection and meta-programming. Ruby's core API, extensive standard library, and thousands of high-quality external libraries make it suitable for many different programming tasks in multiple disciplines key examples being network programming, Web applications, shell scripts, data processing, and text manipulation.
|Published (Last):||26 February 2010|
|PDF File Size:||6.36 Mb|
|ePub File Size:||13.20 Mb|
|Price:||Free* [*Free Regsitration Required]|
Provides a quick reference to the Ruby language, including language elements and many important API functions for quick look-up. Ruby is an easy-to-learn, dynamic, object-oriented programming language with dynamic typing and automatic memory management.
While object-oriented at heart, it provides facilities for procedural and functional programming as well as extensive support for introspection and meta-programming. Ruby's core API, extensive standard library, and thousands of high-quality external libraries make it suitable for many different programming tasks in multiple disciplines key examples being network programming, Web applications, shell scripts, data processing, and text manipulation.
Ruby is considered to be a "pure" object-oriented language because almost every concept within Ruby is object-oriented in some sense. Yukihiro "Matz" Matsumoto, Ruby's creator, wanted to develop a language that operated on the "principle of least surprise" meaning that code should behave in a nonconfusing manner and be reasonably self-explanatory beyond the basic syntax.
Matz also wanted Ruby to be a pleasurable language with which to program, and not make unnecessary demands upon the programmer. Ruby is considered a "reflective" language because it's possible for a Ruby program to analyze itself in terms of its make-up , make adjustments to the way it works, and even overwrite its own code with other code. It's also considered to be "dynamically typed" because you don't need to specify what type of objects can be associated with certain variables.
While everything works on objects and methods called upon those objects behind the scenes, you can write a program as simply as this:.
This script prints to screen the 10th number in the Fibonacci sequence. The use of i. The main Ruby interpreter is usually invoked by running "ruby" from the command line. If it is given a filename as an argument that file will be run e. The interpreter has several other options that are listed in the "Ruby Interpreter Arguments" table in this card's reference section. Developing a program with "true" object-oriented syntax is not significantly different.
For example:. Earlier we called Ruby a "reflective" language because it offers functionality to programs to change, extend, and otherwise inspect themselves. We can look at a key Ruby idiom and reflective feature—class reopening—by changing the Fibonacci example from earlier to the following:. Note this time that in order to get the Fibonacci number, we're no longer calling a global fib method, but a method that works directly upon the number 10 itself remember, everything is an object—even the number 10!
The way this is achieved is by "reopening" a standard Ruby class—Integer—and defining a new method called fib within it. This then makes the fib method available to all objects of class Integer in Ruby! Note that the content of the integer object itself the number we need to use is obtained with the self keyword. In this sense, Ruby is very similar to Python. Anything you type is evaluated by Ruby and the response printed to screen.
IRB can be invoked by running "irb" from the command. A demonstrative session shows the usage:. IRB is most commonly used when learning the Ruby programming language, and also as a handy "sand box" to try out new programming tricks and techniques quickly.
IRB can be used to interactively explore classes, test pieces of code and is also used as a console to inspect and manipulate running programs, for example, in Web applications. RubyGems is the official Ruby package manager though, notably, it is not included with default Ruby 1.
It allows developers and users to easily search, install and update Ruby libraries and their dependencies and works in a similar fashion to other package management tools such as yum and apt-get. Gems are installed by running "gem install" and the name of the gem e. Running "gem update" updates all installed gems to their latest official versions.
The following reference tables provide a quick look at many elements of Ruby's syntax. These can be used as a comparison to other languages in order to see how the syntax differs. Ruby's syntax is often rather different to that of, say, Java or C. Instance methods are written. Ruby 1. It has an entirely new virtual machine and bytecode compiler, formerly known as YARV. The new version includes support for unicode in strings, the famous Oniguruma regular expression engine as well as Operating System Threads and Fibers for lightweight concurrency.
Over a million developers have joined DZone. Refcard Essential Ruby. Published: Nov. Written by. Peter Cooper Manager, Poop Tech. Table of Contents. Section 1. This refcard provides a quick reference to language elements and many important API functions for quick lookup.
Section 2. Section 3. While everything works on objects and methods called upon those objects behind the scenes, you can write a program as simply as this: def fib i if i. Section 4. Want to try Ruby without installing anything? Or want to get a walkthrough tutorial? Section 5. Section 6. Types Integer Fixnum or Bignum 1. Any character excluding newlines [ One or more to as few as possible? Zero or one pipe symbol Alternatives e. Atomic group?
Class class Class class Returns true if the object's class equals the argument. Returns true if the object equals nil.
Symbol methodname Returns true if the object responds to the method. Object object Returns true if the collection includes object. Pushes object to the end of the Array. Returns the index of the last occurrence of object.
Object object Returns true if the hash includes a value for key. Returns true if the collection includes a key for value. Returns the key for value. Returns a new Hash with entries from both Hashes. Returns true if there is no more data to read. Section 7. Section 8. Like This Refcard? Free DZone Refcard. Let's be friends:. Sends all elements to the block and returns true if every block returned true.
Sends all elements to the block and returns the first element for which the blocks result is not false. Sends all elements to the block and returns all elements for which the block is not false. Returns the object at the specified index or all objects in the specified range. Finds all occurrences of regexp and replaces them with the result of the block.
Returns a version of the string with uppercase turned to lowercase and vice-versa.
Essential Ruby Refcard Available - Download Now
This is a product that has nothing to do with PostgreSQL yet, so it does seem kind of odd that we are listing this in our product showcase section. Well it is not even really a product per se, but I was just so enamored by the beauty of the layout and the usefulness of these cheat sheets, that I felt it was worthy of being listed in our showcase section since some of these would be useful to the PostgreSQL community of programmers. What is this product you ask? It is DZone RefCardz.
Ruby is an easy language to learn, but it's often necessary to look up something we've forgotten. A combination of Google plus any Ruby books we have on our shelves can help, but sometimes it's handy to refer to a simpler set of notes - such as a "cheat sheet. The idea for this initial list came from Scott Klarr's own list. Scott has been quite prolific lately in putting together lists of cheat sheets. Essential Ruby is a combination of a cheat sheet and a tutorial.