1 / 16

RUBY

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 .

anise
Télécharger la présentation

RUBY

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RUBY by Ryan Chase

  2. 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.

  3. History of Ruby • Object-oriented • Interpreted • Compilation is not required • Ruby 1.0 released in 1996 • Current Version: Ruby 1.9.1

  4. 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

  5. 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: deftestMethod x = 4+4   end • Missing unary operators in Ruby – Unary operators ++ and — are not supported in Ruby. Instead you can use += operator.

  6. 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  

  7. 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.

  8. 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.

  9. Primitives • Everything is an object with a type associated with it. These include: • Numbers • Fixnum • Bignum • Float • String • Boolean

  10. 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 1 else return (y*factorial(y-1)) end end

  11. 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

  12. 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.

  13. 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.

  14. 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

  15. 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

  16. Conclusion • Ruby Rocks! Get it? • It is a wonderful, all-purpose programming language • It is a very simple-to-use language that gets right to the point • puts “ ” is a lot easier to type than system.out.println(“ “); • Hardly any brackets and no semicolons • I would use this language again!

More Related