1 / 19

W hy Ruby ? H esham Kanany H esham.Kanany@gmail.com

W hy Ruby ? H esham Kanany H esham.Kanany@gmail.com. S cope. History of Ruby. Where can you use Ruby? General Features. Ruby: the Language. Advantages using Ruby against other languages. Some Coding Conventions. Now what?. H istory of Ruby.

ayala
Download Presentation

W hy Ruby ? H esham Kanany H esham.Kanany@gmail.com

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. WhyRuby ? HeshamKanany Hesham.Kanany@gmail.com

  2. Scope History of Ruby. Where can you use Ruby? General Features. Ruby: the Language. Advantages using Ruby against other languages. Some Coding Conventions. Now what?

  3. History of Ruby Created (in Japan) by Yukihiro Matsumoto, popularly called Matz. Matz has stated, "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language" Released to the public in 1995. Licensed under GPL or Ruby terms.

  4. About Ruby • Ruby is… A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. • At a Google Tech Talk in 2008 Matz further stated, "I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language. • Matz has often said that he is “trying to make Ruby natural, not simple,” in a way that mirrors life. • Building on this, he adds: • Ruby is simple in appearance, but is very complex inside, just like our human body. • Write more understandable code in less lines.

  5. Where can you use Ruby? Text processing. web apps. general system administration. AI and math research.

  6. General Features High level language. True OO (everything’s an object!). Interpreted. Highly portable, works on Linux, UNIX, DOS, Windows 95/98/NT/2K, Mac, etc.

  7. Ruby: the Language No multiple inheritance, but modules allow the importing of methods. Has garbage collection. Exception handling, like Java. Any class or instance can be extended any time (even during runtime) . Allows operator overloading. Can be extended with Ruby or low-level C. No type declaration.

  8. Advantages using Ruby against other languages Allow pass by code block. Support Regular Expression. Cleaner code. No need to declare variables. Simple syntax (semi-colon is optional). Every thing is an object, even a number. Simple object get/set methods declaration.

  9. Some Coding Conventions

  10. Just in Ruby :) puts x if !x>5 puts x unless x>5 10.times do ------- End 5.upto 12 do ------- end 100.downto 32 do ------- end

  11. Just in Ruby :) (continue) cat=Animal.new('myCat') def cat.sleep(mouse) #Define a function on the object level ------------- End class Animal def name =(new_name) @name =new_name end end# acts as a setter dog=Animal.new('wolf') dog.name() → 'wolf' dog.name= 'lolo' dog.name → 'lolo'

  12. Ranges Inclusive range my_range = 1 .. 10 1..10 # Creates a range from 1 to 10 Non-inclusive range my_range = 1 … 10 1...10 # Creates a range from 1 to 9 ('cab'..'car').to_a => ["cab", "cac", "cad", "cae", "caf", "cag", "cah", "cai", "caj", "cak", "cal", "cam", "can", "cao", "cap", "caq", "car"]

  13. Data Type Conversion Converting to an Array: var_data_type.to_a Converting to an String: var_data_type.to_s More (guess!): var_data_type.to_i var_data_type.to_f

  14. Everything's an Object Methods can be applied to data directly – not just on variables holding data Example: 5.to_s will return "5"

  15. Iterators array_or_range = value array_or_range.each { |x| print x } Example: my_range = 1..5 my_range.each { |x| print x }

  16. Functions Functions begin with the keyword def def function_name([args]) code block end Example: def print_name(name='Ruby') print name end

  17. OO Ruby Classes are containers for static data members and functions Declared using the class keyword. All class names should begin with a capital letter Constructor declared using the initialize keyword Class variables precede with an “@” Objects created using the new method

  18. Now what? What you can do now? Write simple Ruby programs What you have to do? Find a problem, and Ruby it!

  19. Thank you! Questions?

More Related