Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Started with Ruby

Getting Started with Ruby

Ruby is a dynamic object oriented language that has become increasingly popular in recent years. In this session, we introduce the language, discuss some of its major features and learn how it can boost developer productivity.

Agenda

What is Ruby? (History and Origin)
Why are people using Ruby? (Advantages Over Other Languages)
The Ruby Ecosystem (Ruby Gems, Installer, Editors)
Quick Ruby Tutorial (Loops, Conditionals, Functions, API Docs)
Object Oriented Development in Ruby (Classes, Modules)
Quick Introduction to Ruby on Rails

Session was held at Flat6Labs on 17th, November 2012.

Cairo Tech Club

November 17, 2012
Tweet

More Decks by Cairo Tech Club

Other Decks in Programming

Transcript

  1. RUBY HISTORY •  Ruby was created in 1994 by a

    developer called Yukihiro "Matz" Matsumoto in Japan •  In 2004 David Heinemeier Hansson (DHH) extracted Ruby on Rails from his work on Basecamp, a project management tool by 37signals (now a web application company) •  Rails was a great hit and powered the growth of the Ruby community ever since •  Some of the companies that use Rails: AT&T, NASA, Google, and Living Social
  2. WHAT IS RUBY? •  Ruby is an interpreted language • 

    Ruby is a dynamic and strongly typed language •  x = "3”; y = x + "ho!" #result : "3ho!” •  x = "3”; y = x + 3 #Wooo! Ruby won't like that •  Ruby was built by concepts from many different languages •  First Class Regex – Perl •  Blocks and Closures – Lisp •  Object Oriented – Smalltalk •  Mixins - Objective-C •  Readability - Python
  3. ECOSYSTEM •  Ruby Gems - http://rubygems.org/ •  Installers •  Official

    Ruby Installer - http://www.ruby-lang.org/en/ •  Windows – http://RailsInstaller.org/ •  Also installs rails dependencies •  Unix-like •  RBEnv - https://github.com/fesplugas/rbenv-installer •  RVM - https://rvm.io/ •  Editors •  Text Editor – Textmate, Notepad++, Sublime, gEdit, Vim •  IDE – Aptana, RubyMine
  4. RUBY FEATURES •  Duck Typing •  If it walks like

    a duck and quacks like a duck then it’s a duck •  Everything is an Object •  5 is an object, so 5.to_s •  Open classes •  Ability to modify pre-existing code •  Blocks •  Functional language feature •  Mixins •  Import code from anywhere (solves same problems as interfaces)
  5. LITERALS AND VARIABLES Basic types: •  Numbers: Fixnum, Octal, Binary,

    Float, etc. •  Strings •  Regular Expressions Variables •  local variable: local_variable = 10 •  Instance variable: @instance_variable = 10 •  Class variable: @@instance_variable = 10 •  Global variable: $global_variable = 10 •  Constants: VARIABLE
  6. STRINGS Ruby as similar string constructs like PHP, Perl and

    Python A string can be created using ‘ or “ difference is in the ‘ string escaped char are not evaluated eg. \t, \n, \r Possible ways to create strings in ruby:
  7. SYMBOLS Symbols are defined using : Symbols are global static

    strings Symbols are a type Symbols where created to reduce static string creation Symbols are striped down versions of strings
  8. COLLECTIONS Collections(Arrays) can contain different data types Fetching elements from

    an arrays is using [ ] Same as everything is ruby collections are objects
  9. HASHES Hashes are like associative arrays in Perl, PHP and

    Python and Dictionaries in C# and Java Hashes are simply key value stores It is better to use symbols as keys
  10. BLOCKS Blocks are pieces of code that can be send

    to a method Methods execute blocks by using the keyword yield
  11. OBJECTS, ATTRIBUTES, AND METHODS We define classes using the keyword

    class We define methods using the keyword def
  12. OBJECTS, ATTRIBUTES, AND METHODS We create an instance of the

    class using the new method Calling the new method creates an instance of the class and calls an initialize method Method can return a value using the keyword return or like python return the last evaluated statement
  13. WHAT IS RAILS? •  Rails is a web application development

    framework written in the Ruby language •  It is designed to make programming web applications easier by making assumptions about what every developer needs to get started •  It allows you to write less code while accomplishing more than many other languages and frameworks •  Experienced Rails developers also report that it makes web application development more fun.
  14. RAILS PHILOSOPHY •  DRY – “Don’t Repeat Yourself” •  Convention

    Over Configuration •  REST is the best pattern for web applications •  Representational state transfer
  15. RESOURCES •  Ruby Language Wikipedia •  Ruby on Rails Wikipedia

    •  Try Ruby •  About Ruby •  Ruby Official Page •  Dynamically and Strongly Typed •  Ruby in 100 Minutes •  Ruby Tapas •  Rails Casts