Upload
anise
View
50
Download
0
Tags:
Embed Size (px)
DESCRIPTION
RUBY. b y Ryan Chase. Yukihiro “ Matz ” Matsumoto. The name “Ruby” was chosen before any of the coding for the language was started. It is said to have been the birthstone of a colleague of Matz . - PowerPoint PPT Presentation
Citation preview
Yukihiro “Matz” Matsumoto
•The name “Ruby” was chosen before any of the coding for the language was started. It is said to have been the birthstone of a colleague of Matz.
•When he was first introduced to programming as a student he believed that he could be the designer of an ideal programming language.
•After having researched further, Matz imagined he could create a language more powerful than Perl and even more object-oriented than Python. This is the motivation that drove Matz to the development of Ruby.
History of Ruby Object-oriented Interpreted Compilation is not required Ruby 1.0 released in 1996 Current Version: Ruby 1.9.1
Uses of Ruby Ruby is an all-purpose language. Here is a list of
applications that Ruby would be a suitable programming language to use for development:
Text processing CGI programming Network programming XML programming GUI applications AI and Exploratory Mathematics General programming Prototyping Programming education eXtreme programming
Fast Web Development
Unique Features Everything is an object – Ruby is a pure object-oriented programming language in that
everything is automatically an object. This isn’t true in other object-oriented languages. Here is an example:
5.times { puts "Hello World" }
This simple code will print out “Hello World” five times in a row, each one with a new line. Implicit return value in methods – The value of the last expression in a method
becomes the return value of the method. In Ruby, the return keyword is optional. In the following example, 8 is the return value:
def testMethod
x = 4+4
end
Missing unary operators in Ruby – Unary operators ++ and — are not supported in
Ruby. Instead you can use += operator.
Unique Features Ruby supports parallel assignment – It is possible to change multiple
variables in a single assignment. A good example is the swapping of two variables as given below:
a, b = b, a
In Ruby strings are mutable – In Ruby it is possible to change a string
variable in place. So, unlike Java, the same string when used multiple times will point to different object instances:
print "hello".object_id print "hello".object_id # prints a different value
a = "hello" a[1] = "a"
print a # prints hallo
Unique Features True and false in Ruby – In Ruby only nil and false evaluate to false.
This means that everything else evaluates to true. Hence even the value 0 evaluates to true in ruby. The following code will output “Hello World”:
if (0) then
print "Hello World"
end
Method indicators – In Ruby the last character of a method name can
indicate its behavior. If the method ends with a question mark it indicates that the return value is boolean. If the method ends with an exclamation, it indicates that the method can change the state of the object. In many cases a non exclamation version of the method is provided which modifies a copy of the object.
Ruby is a Hybrid Ruby is a hybrid of iterative, functional,
and declarative, just like C++ and Java because it is object oriented. Ruby can do declarative things, but also can do much more. Therefore, it is definitely a hybrid.
Primitives Everything is an object with a type
associated with it. These include: Numbers
Fixnum Bignum Float
String Boolean
Combining Features Ruby combines its features in a very standard
way. Here is an example from a factorial program that shows how different features can be combined:
def factorial(y)if y==0 return 1else return (y*factorial(y-1))endend
Abstraction Methods of abstraction can be features of
the language that allow you to focus on the algorithm and be less worried about the computer’s needs.
Examples of Methods of Abstraction: Variables Objects Arrays Classes Functions Loops
Return Values Ruby does not have to return values in its
methods and it can return values just like we are used to with other languages like Java and C++.
If the return value is not specified (by the keyword “return”) at the end of a method, the value of the last expression in the method is defined as the return value of the method.
First Class In Ruby you can pass functions into
other functions.
You can return functions from other functions
Ruby allows you to nest functions inside of other functions.
More Features The way Ruby passes its variables in by
value, not by reference, result, or name. Has type errors, cannot perform
arithmetic expressions on strings, etc. Ruby does NO automatic type checking Ruby is a strong dynamic typed language Ruby does coerce types, but it does
change the type for you in the background Ruby uses type inference
Dynamic, Static, and Inheritance Ruby provides single inheritance All classes inherit from a common
parent. The variable inheritance is static The method inheritance is dynamic Super-method invocation is handled
statically