| Ruby |
 | | Paradigm | multi-paradigm (functional, imperative, logic, object-oriented (class-based)) | | Appeared in | 1995 | | Designed by | Yukihiro Matsumoto | | Developer | Yukihiro Matsumoto (among others) | | Latest release | 1.8.6/ March 12, 2007 | | Typing discipline | dynamic ("duck") | | Major implementations | Ruby, JRuby | | Influenced by | Smalltalk, Perl, Lisp, Scheme, Python, CLU, Eiffel, Ada, Dylan | | Influenced | Groovy | | OS | Cross-platform | | License | Ruby License and GPL | | Website | www.ruby-lang.org | Ruby is a reflective, dynamic, object-oriented programming language. It combines syntax inspired by Perl with Smalltalk-like object-oriented features, and also shares some features with Python, Lisp, Dylan, and CLU. Ruby is a single-pass interpreted language. Its official implementation is free software written in C. Image File history File links No higher resolution available. ...
A programming paradigm is a paradigmatic style of programming (compare with a methodology, which is a paradigmatic style of doing software engineering). ...
This does not cite any references or sources. ...
Yukihiro Matsumoto , a. ...
For other uses, see Software developer (disambiguation). ...
A software release refers to the creation and availability of a new version of a computer software product. ...
is the 71st day of the year (72nd in leap years) in the Gregorian calendar. ...
Year 2007 (MMVII) is the current year, a common year starting on Monday of the Gregorian calendar and the AD/CE era in the 21st century. ...
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ...
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ...
Duck typing is a style of dynamic typing in which an objects current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class. ...
Look up Implementation in Wiktionary, the free dictionary. ...
JRuby is a Java implementation of the Ruby interpreter, being developed by the JRuby team. ...
For other uses, see Small talk. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ...
Scheme is a multi-paradigm programming language. ...
Python is a high-level programming language first released by Guido van Rossum in 1991. ...
CLU is a programming language created at MIT by Barbara Liskov and her students between 1974 and 1975. ...
Eiffel is an object-oriented programming language which emphasizes the production of robust software. ...
Ada is a structured, statically typed, imperative, and object-oriented high-level computer programming language. ...
The Dylan programming language (pronounced , like the name) is functional, object-oriented, reflective and dynamic. ...
In slang and informal language, Groovy refers to a fashionable or desirable quality, without necessarily specifying one. ...
An operating system (OS) is the software that manages the sharing of the resources of a computer and provides programmers with an interface used to access those resources. ...
A cross-platform (or platform independent) programming language, software application or hardware device works on more than one system platform (e. ...
A software license is a legal agreement which may take the form of a proprietary or gratuitous license as well as a memorandum of contract between a producer and a user of computer software. ...
The GNU logo The GNU General Public License (GNU GPL or simply GPL) is a widely-used free software license, originally written by Richard Stallman for the GNU project. ...
A website (alternatively, Web site or web site) is a collection of Web pages, images, videos or other digital assets that is hosted on one or several Web server(s), usually accessible via the Internet, cell phone or a LAN. A Web page is a document, typically written in HTML...
In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior. ...
Dynamic programming language is a term used broadly in computer science to describe a class of high level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. ...
An object-oriented programming language (also called an OO language) is one that allows or encourages, to some degree, object-oriented programming techniques such as encapsulation, inheritance, interfaces, and polymorphism. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
For other uses, see Small talk. ...
Python is a high-level programming language first released by Guido van Rossum in 1991. ...
âLISPâ redirects here. ...
Dylan is a dynamic programming language created by a group led by Apple Computer. ...
CLU is a programming language created at MIT by Barbara Liskov and her students between 1974 and 1975. ...
In computer programming, an interpreted language is a programming language whose programs may be executed from source form, by an interpreter. ...
Clockwise from top: The logo of the GNU Project, the Linux kernel mascot Tux, and the BSD Daemon Free software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions only...
C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
History
Yukihiro Matsumoto, the creator of 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 [1]. Image File history File links No higher resolution available. ...
Image File history File links No higher resolution available. ...
Yukihiro Matsumoto , a. ...
is the 55th day of the year in the Gregorian calendar. ...
Year 1993 (MCMXCIII) was a common year starting on Friday (link will display full 1993 Gregorian calendar). ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
As of March 2007, the latest stable version is 1.8.6. Ruby 1.9 (with some major changes) is also in development. Poor performance of the current Ruby implementation in comparison to other more entrenched programming languages has led to the development of several virtual machines for Ruby. These include JRuby, a port of Ruby to the Java platform, IronRuby, an implementation for the .NET Framework produced by Microsoft, and Rubinius, an interpreter modeled after self-hosting Smalltalk virtual machines. The main developers have thrown their weight behind the virtual machine provided by the YARV project, which was merged into the Ruby source tree on 31 December 2006, and will be released as Ruby 2.0. JRuby is a Java implementation of the Ruby interpreter, being developed by the JRuby team. ...
âJava languageâ redirects here. ...
IronRuby is an implementation of the Ruby programming language targeting Microsoft . ...
The Microsoft . ...
Microsoft Corporation, (NASDAQ: MSFT, HKSE: 4338) is a multinational computer technology corporation with global annual revenue of US$44. ...
// Rubinius is a next-generation virtual machine and compiler for Ruby created by Evan Phoenix. ...
Self-hosting refers to the use of a computer program as part of the toolchain or operating system that produces new versions of that same programâfor example, a compiler that can compile its own source code. ...
For other uses, see Small talk. ...
YARV (Yet Another Ruby VM) is the new bytecode interpreter that is being developed for the Ruby programming language by Koichi Sasada. ...
is the 365th day of the year (366th in leap years) in the Gregorian calendar. ...
Year 2006 (MMVI) was a common year starting on Sunday of the Gregorian calendar. ...
Philosophy The language's creator has said that Ruby is designed for programmer productivity and fun, following the principles of good user interface design.[2] He stresses that systems design needs to emphasize human, rather than computer, needs [3]: The user interface is the part of a system exposed to users. ...
| “ | Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves. | ” | Ruby is said to follow the principle of least surprise (POLS), meaning that the language should behave in such a way as to minimize confusion for experienced users. Matz has said his primary design goal was to make a language that he himself enjoyed using, by minimizing programmer work and possible confusion. He has said he hadn't applied the principle of least surprise to the design of Ruby,[4] but nevertheless the phrase has come to be closely associated with the Ruby programming language. The phrase has itself been a source of surprise, as novice users may take it to mean that Ruby's behaviors try to closely match behaviors familiar from other languages. In a May 2005 discussion on the comp.lang.ruby newsgroup, Matz attempted to distance Ruby from POLS, explaining that since any design choice will be surprising to someone, he uses a personal standard in evaluating surprise. If that personal standard remains consistent there will be few surprises for those familiar with the standard. [1] In science, the informal principle of least astonishment, also known as the principle of maximum boredom, states that the explanation which is the least astonishing and which is the most boring is usually (but not always) the right one. ...
Matz defined it this way in an interview [2]: | “ | Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, 'I was surprised by this feature of the language, so Ruby violates the principle of least surprise.' Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me. | ” | Semantics Ruby is object-oriented: every data type is an object, including even classes and types that many other languages designate as primitives (such as integers, booleans, and "nil"). Every function is a method. Named values (variables) always designate references to objects, not the objects themselves. Ruby supports inheritance with dynamic dispatch, mixins and singleton methods (belonging to, and defined for, a single instance rather than being defined on the class). Though Ruby does not support multiple inheritance, classes can import modules as mixins. Procedural syntax is supported, but all methods defined outside of the scope of a particular object are actually methods of the Object class. Since this class is parent to every other class, the changes become visible to all classes and objects. Object-oriented programming (OOP) is a computer programming paradigm in which a software system is modeled as a set of objects that interact with each other. ...
The integers are commonly denoted by the above symbol. ...
In computer science, a subroutine (function, procedure, or subprogram) is a sequence of code which performs a specific task, as part of a larger program, and is grouped as one, or more, statement blocks; such code is sometimes collected into software libraries. ...
Used mainly in object-oriented programming, the term method refers to a piece of code that is exclusively associated either with a class (called class methods or static methods) or with an object (called instance methods). ...
In object-oriented programming of computer science, an inheritance is a way to form new classes (instances of which will be objects) using pre-defined objects or classes where new ones simply take over old ones implementations and characteristics. ...
In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code (method) at runtime. ...
In object-oriented programming languages, a mixin is an approach to implementing classes that differs from the most widely-used approach coming from the programming language Simula. ...
In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. ...
An object is fundamental concept in object-oriented programming. ...
Multiple inheritance refers to a feature of object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. ...
It has been suggested that this article or section be merged into Modularity (programming). ...
Ruby has been described as a multi-paradigm programming language: it allows procedural programming (defining functions/variables outside classes makes them part of the root, 'self' Object), with object orientation (everything is an object) or functionally (it has anonymous functions, closures, and continuations; statements all have values, and functions return the last evaluation). It has support for introspection, reflection and metaprogramming, as well as support for interpreter-based[5] threads. Ruby features dynamic typing, and supports parametric polymorphism. This does not cite any references or sources. ...
Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. ...
An anonymous function is a function (or a subroutine) defined, and possibly called, without being bound to a name. ...
In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. ...
In computing, a continuation is a representation of some of the execution state of a program (often the call stack and the current Instruction pointer) at a certain point. ...
In computing, type introspection is a capability of some object-oriented programming languages to determine the type of an object at runtime. ...
In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior. ...
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data or that do part of the work during compile time that is otherwise done at run time. ...
For the form of code consisting entirely of subroutine calls, see Threaded code. ...
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ...
In simple terms, polymorphism lets you treat derived class members just like their parent classs members. ...
According to the Ruby FAQ [6], "If you like Perl, you will like Ruby and be right at home with its syntax. If you like Smalltalk, you will like Ruby and be right at home with its semantics. If you like Python, you may or may not be put off by the huge difference in design philosophy between Python and Ruby/Perl." [7] FAQ is an abbreviation for Frequently Asked Question(s). The term refers to listed questions and answers, all supposed to be frequently asked in some context, and pertaining to a particular topic. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
For other uses, see Small talk. ...
Python is a high-level programming language first released by Guido van Rossum in 1991. ...
Features Ruby currently lacks full support for Unicode, though it has partial support for UTF-8. Object-oriented programming (OOP) is a computer programming paradigm in which a software system is modeled as a set of objects that interact with each other. ...
In computer programming, a global variable is a variable that is accessible in every scope. ...
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. ...
In computer science, an iterator is an object which allows a programmer to traverse through all the elements of a collection, regardless of its specific implementation. ...
In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
In computing, a regular expression is a string that is used to describe or match a set of strings, according to certain syntax rules. ...
In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == have different implementations depending on the types of their arguments. ...
In computer science, garbage collection (GC) is a form of automatic memory management. ...
In computer science, porting is the process of adapting software so that an executable program can be created for a computing environment that is different from the one for which it was originally designed (e. ...
Many programming languages, operating systems, and other software development environments support what are called threads of execution. ...
A thread in computer science is short for a thread of execution. ...
Dynamic-link library (also written without the hyphen), or DLL, is Microsofts implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems. ...
Illustration of an application which may use libvorbisfile. ...
In computing, type introspection is a capability of some object-oriented programming languages to determine the type of an object at runtime. ...
In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior. ...
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data or that do part of the work during compile time that is otherwise done at run time. ...
Dependency injection (DI) is a programming architectural model, sometimes also referred to as inversion of control or IOC although, technically speaking, dependency injection specifically refers to an implementation of a particular form of IOC. // Dependency Injection describes the situation where one object uses a second object to provide a particular...
Dynamic programming language is a term used broadly in computer science to describe a class of high level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. ...
In computing, a continuation is a representation of some of the execution state of a program (often the call stack and the current Instruction pointer) at a certain point. ...
In computer science, a generator is a special routine that can be used to control the iteration behaviour of a loop. ...
The Unicode Standard, Version 5. ...
UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. ...
Interaction - See also: Interactive Ruby Shell
The Ruby official distribution also includes "irb", an interactive command-line interpreter which can be used to test code quickly. The following code fragment represents a sample session using irb: Interactive Ruby Shell (IRB) is a shell for programming in the object-oriented scripting language Ruby. ...
$ irb irb(main):001:0> puts "Hello, World" Hello, World => nil irb(main):002:0> 1+2 => 3 Syntax The syntax of Ruby is broadly similar to Perl and Python. Class and method definitions are signaled by keywords. In contrast to Perl, variables are not obligatorily prefixed with a sigil. When used, the sigil changes the semantics of scope of the variable. The most striking difference from C and Perl is that keywords are typically used to define logical code blocks, without braces (i.e., pair of { and }). Line breaks are significant and taken as the end of a statement; a semicolon may be equivalently used. Unlike Python, indentation is not significant. In computer programming, a sigil is a symbol attached to a variable name, showing the variables datatype. ...
One of the differences of Ruby compared to Python and Perl is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc). Unlike the "getter" and "setter" methods of other languages like C++ or Java, accessor methods in Ruby can be written with a single line of code. As invocation of these methods does not require the use of parentheses, it is trivial to change an instance variable into a full function, without modifying a single line of code or having to do any refactoring achieving similar functionality to C# and VB.NET property members. Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision by forcing all instance variables to be private, but also provides a simple way to declare set and get methods. This is in keeping with the idea that in Ruby, one never directly accesses the internal members of a class from outside of it. Rather one passes a message to the class and receives a response. See the examples section for samples of code demonstrating Ruby syntax.
"Gotchas" Language comparison Some features that differ notably from languages such as C or Perl: C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
- Names that begin with a capital letter are treated as constants, so local variables should begin with a lowercase letter.
- The symbols
$ @ are not sigils as in Perl, but rather function as scope resolution operators. - To denote floating point numbers, one must follow with a zero digit (
99.0) or an explicit conversion (99.to_f). It is insufficient to append a dot (99.) because numbers are susceptible to method syntax. - Boolean evaluation of non-boolean data is strict: 0,
"" and [] are all evaluated to true. In C, the expression 0 ? 1 : 0 evaluates to 0 (i.e. false). In Ruby, however, it yields 1, as all numbers evaluate to true; only nil and false evaluate to false. A corollary to this rule is that Ruby methods by convention — for example, regular-expression searches — return numbers, strings, lists, or other non-false values on success, but nil on failure (e.g., mismatch). This convention is also used in Smalltalk, where only the special objects true and false can be used in a boolean expression. - Versions prior to 1.9 lack a character data type (compare to C, which provides type
char for characters). This may cause surprises when slicing strings: "abc"[0] yields 97 (an integer, representing the ASCII code of the first character in the string); to obtain "a" use "abc"[0,1] (a substring of length 1) or "abc"[0].chr. - The notation "statement until expression", despite the English-language implication that the statement would be executed at least once, which follows the precedent used in other languages' equivalent statements (e.g. "do { statement } while (not(expression));" in C/C++/...), actually never runs the statement if the expression is already true.
- Because constants are references to objects, changing what a constant refers to generates a warning, but modifying the object itself does not. For example, if Greeting = "Hello" then Greeting << " world!" does not generate an error or warning.
In computer programming, a sigil is a symbol attached to a variable name, showing the variables datatype. ...
The scope resolution operator (::) in c++ is used to define the already declared member functions (in the header file with the . ...
In computer science, the Boolean datatype, sometimes called the logical datatype, is a primitive datatype having two values: one and zero (which are equivalent to true and false). ...
In computing, a regular expression is a string that is used to describe or match a set of strings, according to certain syntax rules. ...
Image:ASCII fullsvg There are 95 printable ASCII characters, numbered 32 to 126. ...
Language features - In terms of speed, Ruby's performance is inferior to that of many compiled languages (as is any interpreted language) and other major scripting languages such as Python and Perl[9]. However, in future releases (current revision: 1.9), Ruby will be bytecode compiled to be executed on YARV (Yet Another Ruby VM). Currently, Ruby's memory footprint for the same operations is higher than Perl's and Python's.[9]
- Omission of parentheses around method arguments may lead to unexpected results if the methods take multiple parameters. Note that the Ruby developers have stated that omission of parentheses on multi-parameter methods may be disallowed in future Ruby versions, the Ruby interpretor currently (Nov 2007) throws a warning which encourages the writer to NOT omit (), to avoid ambigous meaning of code. Not using () is however still common practise, and can be especially nice to use Ruby as a human readable domain-specific language itself, along with the method called method_missing().
Much existing literature, however, encourages parenthesis omission for single-argument methods.[citation needed] Python is a high-level programming language first released by Guido van Rossum in 1991. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
Bytecode is a binary representation of an executable program designed to be executed by a virtual machine rather than by dedicated hardware. ...
YARV (Yet Another Ruby VM) is the new bytecode interpreter that is being developed for the Ruby programming language by Koichi Sasada. ...
A list of "gotchas" may be found in Hal Fulton's book The Ruby Way, 2nd ed (ISBN 0-672-32884-4), Section 1.5. A similar list in the 1st edition pertained to an older version of Ruby (version 1.6), some problems of which have been fixed in the meantime. retry, for example, now works with while, until, and for, as well as iterators. For other uses of Gotcha, see Gotcha (disambiguation). ...
Examples Classic Hello world example: A hello world program is a computer program that prints out Hello, world! on a display device. ...
Some basic Ruby code: # Everything, including a literal, is an object, so this works: -199.abs # 199 "ruby is cool".length # 12 "Rick".index("c") # 2 "Nice Day Isn't It?".downcase.split(//).uniq.sort.join # " '?acdeinsty" Collections Constructing and using an array: This article does not cite any references or sources. ...
a = [1, 'hi', 3.14, 1, 2, [4, 5]] a[2] # 3.14 a.reverse # [[4, 5], 2, 1, 3.14, 'hi', 1] a.flatten.uniq # [1, 'hi', 3.14, 2, 4, 5] Constructing and using a hash: In computer science, a hash table is a data structure that speeds up searching for information by a particular aspect of that information, called a key. ...
hash = {:water => 'wet', :fire => 'hot'} puts hash[:fire] # Prints: hot hash.each_pair do |key, value| # Or: hash.each do |key, value| puts "#{key} is #{value}" end # Prints: water is wet # fire is hot hash.delete_if {|key, value| key == :water} # Deletes :water => 'wet' Blocks and iterators The two syntaxes for creating a code block: { puts "Hello, World!" } # Note the { braces } do puts "Hello, World!" end Parameter-passing a block to be a closure: In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. ...
# In an object instance variable (denoted with '@'), remember a block. def remember(&a_block) @block = a_block end # Invoke the above method, giving it a block that takes a name. remember {|name| puts "Hello, #{name}!"} # When the time is right (for the object) -- call the closure! @block.call("Jon") # => "Hello, Jon!" Returning closures from a method: def create_set_and_get(initial_value=0) # Note the default value of 0 closure_value = initial_value return Proc.new {|x| closure_value = x}, Proc.new { closure_value } end setter, getter = create_set_and_get # ie. returns two values setter.call(21) getter.call # => 21 Yielding the flow of program control to a block which was provided at calling time: def use_hello yield "hello" end # Invoke the above method, passing it a block. use_hello {|string| puts string} # => 'hello' Iterating over enumerations and arrays using blocks: array = [1, 'hi', 3.14] array.each {|item| puts item} # => 1 # => hi # => 3.14 (3..6).each {|num| puts num} # => 3 # => 4 # => 5 # => 6 A method such as inject() can accept both a parameter and a block. Inject iterates over each member of a list, performing some function on while retaining an aggregate. This is analogous to the foldl function in functional programming languages. For example: In functional programming, fold or reduce or accumulate is a family of higher-order functions that process a data structure in some order and build up a return value. ...
Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions. ...
[1,3,5].inject(10) {|sum, element| sum + element} # => 19 On the first pass, the block receives 10 (the argument to inject) as sum, and 1 (the first element of the array) as element, This returns 11. 11 then becomes sum on the next pass, which is added to 3 to get 14. 14 is then added to 5, to finally return 19. Blocks work with many built-in methods: File.open('file.txt', 'w') do |file| # 'w' denotes "write mode". file.puts 'Wrote some text.' end # File is automatically closed here File.readlines('file.txt').each do |line| puts line end # => Wrote some text. Using an enumeration and a block to square the numbers 1 to 10: (1..10).collect {|x| x*x} # => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] Classes The following code defines a class named Person. In addition to 'initialize', the usual constructor to create new objects, it has two methods: one to override the <=> comparison operator (so Array#sort can sort by age) and the other to override the to_s method (so Kernel#puts can format its output). Here, "attr_reader" is an example of metaprogramming in Ruby: "attr_accessor" defines getter and setter methods of instance variables, "attr_reader" only getter methods. Also, the last evaluated statement in a method is its return value, allowing the omission of an explicit 'return'. class Person def initialize(name, age) @name, @age = name, age end def <=>(person) # Comparison operator for sorting @age <=> person.age end def to_s "#@name (#@age)" end attr_reader :name, :age end group = [ Person.new("Jon", 20), Person.new("Marcus", 63), Person.new("Ash", 16) ] puts group.sort.reverse The above prints three names in reverse age order: Marcus (63) Jon (20) Ash (16) Exceptions An exception is raised with a raise call: An optional message can be added to the exception: raise "This is a message" You can also specify which type of exception you want to raise: raise ArgumentError, "Illegal arguments!" Exceptions are handled by the rescue clause. Such a clause can catch exceptions that inherit from StandardError: begin # Do something rescue # Handle exception end Note that it is a common mistake to attempt to catch all exceptions with a simple rescue clause. To catch all exceptions one must write: begin # Do something rescue Exception # don't write just rescue -- this only catches StandardError, a subclass of Exception # Handle exception end Or catch particular exceptions: begin # ... rescue RuntimeError # handling end It is also possible to specify that the exception object be made available to the handler clause: begin # ... rescue RuntimeError => e # handling, possibly involving e, such as "print e.to_s" end Alternatively, the most recent exception is stored in the magic global $!.
You can also catch several exceptions: begin # ... rescue RuntimeError, Timeout::Error => e # handling, possibly involving e end Or catch an array of exceptions: array_of_exceptions = [RuntimeError, Timeout::Error] begin # ... rescue *array_of_exceptions => e # handling, possibly involving e end More examples More sample Ruby code is available as algorithms in the following articles: Exponentiating by squaring is an algorithm used for the fast computation of large integer powers of a number. ...
An associative array (also map, hash, dictionary, finite map, lookup table, and in query-processing an index or index file) is an abstract data type composed of a collection of keys and a collection of values, where each key is associated with one value. ...
The Trabb Pardo-Knuth algorithm is a program introduced by Donald Knuth and Luis Trabb Pardo to illustrate the evolution of computer programming languages. ...
Implementations Ruby has two main implementations: The official Ruby interpreter (often referred to as the MRI or Matz's Ruby Interpreter), which is the most widely used, and JRuby, a Java-based implementation. An interpreter is a computer program that executes other programs. ...
JRuby is a Java implementation of the Ruby interpreter, being developed by the JRuby team. ...
âJava languageâ redirects here. ...
There are other less known implementations such as IronRuby (pre-alpha sources available on August 31st, 2007[10]), Rubinius, Ruby.NET, XRuby and YARV. YARV is sometimes referred as the next official Ruby engine. IronRuby is an implementation of the Ruby programming language targeting Microsoft . ...
Software development stages In computer programming, development stage terminology expresses how the development of a piece of software has progressed and how much further development it may require. ...
// Rubinius is a next-generation virtual machine and compiler for Ruby created by Evan Phoenix. ...
YARV (Yet Another Ruby VM) is the new bytecode interpreter that is being developed for the Ruby programming language by Koichi Sasada. ...
Operating systems Ruby is available for the following operating systems: An operating system (OS) is the software that manages the sharing of the resources of a computer and provides programmers with an interface used to access those resources. ...
Other ports may also exist. Acorn Computers Ltd. ...
This article does not cite any references or sources. ...
This article is about the family of home computers. ...
BeOS is an operating system for personal computers which began development by Be Inc. ...
This article is about the family of closely related operating systems for the IBM PC compatible platform. ...
This article is about operating systems that use the Linux kernel. ...
Mac OS X (IPA: ) is a line of graphical operating systems developed, marketed, and sold by Apple Inc. ...
Maemo is a development platform for handheld devices. ...
âWindowsâ redirects here. ...
Windows CE (sometimes abbreviated WinCE) is a variation of Microsofts Windows operating system for minimalistic computers and embedded systems. ...
MorphOS is a mixed proprietary and open source operating system produced for the Pegasos PowerPC (PPC)-processor-based computer, most models of PPC-accelerated classic Amiga computers, and the EFIKA PPC consumer device. ...
To meet Wikipedias quality standards, this article or section may require cleanup. ...
OpenVMS[1] (Open Virtual Memory System or just VMS) is the name of a high-end computer server operating system that runs on the VAX[2] and Alpha[3] family of computers developed by Digital Equipment Corporation of Maynard, Massachusetts (DIGITAL was then purchased by Compaq, and is now owned...
Syllable is a free and open source operating system for Intel x86 Pentium and compatible processors. ...
Symbian OS is a proprietary operating system, designed for mobile devices, with associated libraries, user interface frameworks and reference implementations of common tools, produced by Symbian Ltd. ...
Blue Gene/L Blue Gene is computer architecture project designed to produce several next generation super computers, operating in the PFLOPS range. ...
Filiation of Unix and Unix-like systems Unix (officially trademarked as UNIX®, sometimes also written as or ® with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy. ...
Licensing terms The Ruby interpreter and libraries are distributed disjointedly (dual licensed) under the free and open source licenses GPL and Ruby License [11]. // Licenses are granted by copyright holders to grant exceptions of copyright law to users for a work. ...
Clockwise from top: The logo of the GNU Project, the Linux kernel mascot Tux, and the BSD Daemon Free software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions only...
Open source refers to projects that are open to the public and which draw on other projects that are freely available to the general public. ...
The GNU logo The GNU General Public License (GNU GPL or simply GPL) is a widely-used free software license, originally written by Richard Stallman for the GNU project. ...
Criticism The current 1.8 version of Ruby main interpreter has some limitations. On 1 January 2007, work had begun for version 1.9 which is planned to be released as Ruby 1.9.1 in December 2007. The problems of the current stable version include: is the 1st day of the year in the Gregorian calendar. ...
Year 2007 (MMVII) is the current year, a common year starting on Monday of the Gregorian calendar and the AD/CE era in the 21st century. ...
- As a dynamic scripting language, Ruby's speed is much less than that of other languages, including scripting languages such as Perl, PHP, or Python [3] [4]. However, the next version of Ruby will include a new, faster interpreter, YARV.
- The Ruby threading model uses green threads [5], and its model has some inherent limitations that render it difficult to use or unsafe for some user-case scenarios.[6] - however, version 2.0 of Ruby will not implement green threads,
- Ruby does not yet have native support for Unicode or multibyte strings [7] (expected in version 1.9).
- Ruby support global variable, universally accessible variables which considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity[12].
Some problems that may not be solved in version 2.0 include: Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
For other uses, see PHP (disambiguation). ...
Python is a high-level programming language first released by Guido van Rossum in 1991. ...
YARV (Yet Another Ruby VM) is the new bytecode interpreter that is being developed for the Ruby programming language by Koichi Sasada. ...
A thread in computer science is short for a thread of execution. ...
The Unicode Standard, Version 5. ...
In computer programming, a global variable is a variable that is accessible in every scope. ...
- Ruby still lacks a specification, the current reference specification being the de facto C implementation. [8] [9] .
Repositories and libraries The Ruby Application Archive (RAA), as well as RubyForge, serve as repositories for a wide range of Ruby applications and libraries, containing more than two thousand items. Although the number of applications available does not match the volume of material available in the Perl or Python community, there are a wide range of tools and utilities which serve to foster further development in the language. Ruby Application Archive is a repository of applications for Ruby programming language development. ...
RubyForge is a collaborative software development management system delicated to projects related Ruby programming language. ...
Wikibooks has a book on the topic of Perl Programming Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
Python is a high-level programming language first released by Guido van Rossum in 1991. ...
RubyGems has become the standard package manager for Ruby libraries. It is very similar in purpose to Perl's CPAN, although its usage is more like apt-get. RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called gems), a tool to easily manage the installation of gems, and a server for distributing them. ...
CPAN is an acronym standing for Comprehensive Perl Archive Network. ...
Advanced Packaging Tool, or APT, is a package management system used by the Debian project. ...
References A thread in computer science is short for a thread of execution. ...
Year 2006 (MMVI) was a common year starting on Sunday of the Gregorian calendar. ...
is the 258th day of the year (259th in leap years) in the Gregorian calendar. ...
Year 2007 (MMVII) is the current year, a common year starting on Monday of the Gregorian calendar and the AD/CE era in the 21st century. ...
is the 305th day of the year (306th in leap years) in the Gregorian calendar. ...
Year 2007 (MMVII) is the current year, a common year starting on Monday of the Gregorian calendar and the AD/CE era in the 21st century. ...
is the 243rd day of the year (244th in leap years) in the Gregorian calendar. ...
See also Image File history File links Free_Software_Portal_Logo. ...
Duck typing is a style of dynamic typing in which an objects current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class. ...
Programming languages are used for controlling the behavior of a machine (often a computer). ...
WATIR, pronounced Water, is an acronym standing for Web Application Testing in Ruby. Watir is a toolkit used to automate browser-based tests during web application development. ...
NetBeans refers to both a platform for the development of Java desktop applications, and an integrated development environment (IDE) developed using the NetBeans Platform. ...
External links | Ruby programming language | Interpreters: ERuby · Hackety Hack · Interactive Ruby Shell · IronRuby · JRuby · Mod ruby · Mongrel (web server) · Rinda · SketchUp Ruby · YARV Libraries: Camping (microframework) · Cerise (web framework) · IOWA (web framework) · Nitro (web_framework) · Ramaze (web framework) · RichRuby · RubyGems · Ruby on Rails · WEBrick Development-related: RadRails · Rake (software) · Ruby Application Archive · Ruby Document format · RubyForge · Why's (poignant) Guide to Ruby Image File history File links Wikibooks-logo-en. ...
Wikibooks logo Wikibooks, previously called Wikimedia Free Textbook Project and Wikimedia-Textbooks, is a wiki for the creation of books. ...
Image File history File links This is a lossless scalable vector image. ...
Wikiversity logo Wikiversity is a Wikimedia Foundation beta project[1], devoted to learning materials and activities, located at www. ...
The Open Directory Project (ODP), also known as dmoz (from , its original domain name), is a multilingual open content directory of World Wide Web links owned by Netscape that is constructed and maintained by a community of volunteer editors. ...
The correct title of this article is . ...
Hackety Hack is a free Ruby-based environment aiming to make programming easily available to beginners, especially children. ...
Interactive Ruby Shell (IRB) is a shell for programming in the object-oriented scripting language Ruby. ...
IronRuby is an implementation of the Ruby programming language targeting Microsoft . ...
JRuby is a Java implementation of the Ruby interpreter, being developed by the JRuby team. ...
mod_ruby is a embedded Ruby interpreter of the Apache web server to allow Ruby code executing natively and faster than other CGI methods. ...
Mongrel is an open-source HTTP library and web server for Ruby web applications written by Zed A. Shaw. ...
In Norse mythology, Rindr (sometimes Anglicized Rind) is alternatively described as a giantess, a goddess or a human princess from the east (somewhere in present-day Russia). ...
Ruby is a popular scripting language that was first introduced (to Sketchup) in SketchUp 4. ...
YARV (Yet Another Ruby VM) is the new bytecode interpreter that is being developed for the Ruby programming language by Koichi Sasada. ...
Camping is a web framework which consistently stays at less than 4kb of code. ...
Cerise is a web/application server following the same general pattern as J2EE application servers, but written in the Ruby programming language and providing a very flexible, elegant, lightweight, and developer friendly environment for building web applications. ...
IOWA is a framework, written in the Ruby programming language, for the development of both web based applications and more general dynamic web content. ...
Nitro is a Ruby based web application framework. ...
Ramaze is a modular Web framework written in the Ruby programming language. ...
Introduction:- Rich Ruby is a framework for Web 2. ...
RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called gems), a tool to easily manage the installation of gems, and a server for distributing them. ...
Ruby on Rails is a free web application framework that aims to increase the speed and ease with which database-driven web sites can be created and offers skeleton code frameworks (scaffolding) from the outset. ...
WEBrick is an Ruby library providing simple HTTP web server services. ...
This article does not cite any references or sources. ...
Rake is a software build tool. ...
Ruby Application Archive is a repository of applications for Ruby programming language development. ...
RD is a multi-purpose document format for writing Ruby related documents. ...
RubyForge is a collaborative software development management system delicated to projects related Ruby programming language. ...
Whys (poignant) Guide to Ruby, sometimes called W(p)GtR or just the poignant guide, is an introductory book to the Ruby programming language, written by why the lucky stiff. ...
| |