Ruby for PHPDevelopers                      By Max Titov                       maxtitov.me         Ninja Software Operations
Objective: learn and compare▶   What is Ruby and where it is come from?▶   Why Ruby?▶   Ruby basics▶   Ruby ecosystem▶   R...
Facts▶   First “Hello World” in 1995 (PHP 1995 too)▶   Opensource (PHP too)▶   Inspired by: Perl, Smalltalk, Lisp, Python ...
Creator"I wanted a scripting language that wasmore powerful than Perl, and more object-oriented than Python. Thats why I d...
Why Ruby?▶   It’s fun!▶   It’s going to make your better.▶   And definitely it will sabotage what you    believe in.
Similarities▶   Ruby has exception handling▶   Garbage collector▶   The is fairly large standard library▶   The are classe...
Ruby is Dynamic▶   No need to declare variablesvar = “World in hell”var.class #Stringvar = 1var.class #Fixnum
Ruby is Strong Typed▶   Like in Java or C# there is no type    juggling.    You need to convert between types.a = “1”b=2a ...
Everything is an Object▶   Inspired by SmallTalk▶   Unlike other programming languages that    states the same, Ruby reall...
Everything is an Object▶   Primitive Types are an objects10.times {puts “I am sexy and I know it!”}#Output “I am sexy and ...
Everything is an Object▶   Control structures are object methods    class Fixnum < Integer       def – numeric         # s...
Ruby is Flexible▶   Existing ruby code could be easily altered.    class Numeric       def toSquare         self * self   ...
Duck typing▶   Definition: When I see a bird that walks    like a duck and swims like a duck and    quacks like a duck, I ...
Duck typingWhat makes object an object?        Answer is a: Behavior
So, is it a duck?Swim? YesCan Quack? YesIs it a duck?Definitely!
And this?Swim? YesCan Quack? Yes. Kind ofstrange, but still itmake quack like soundIs it a duck?Looks like!
How, about this?Swim? Badly, but yes.Can Quack? Yeah, makePlenty of sounds but, canquack also.Is it a duck?Sort of weird d...
Or, probably this?Swim? YepCan quack? Canmake weird quacksounds.Is it duck?Trying very hard, soyes 
Duck Typing▶   So, everything that could respond to    several criterias that makes us believe    that it’s a duck, is a d...
Duck Typing in context of Ruby▶   There is no abstract classes and    interfaces.▶   There is Modules and Mixins.
Modules and Mixins▶   Modules define reusable pieces of code    that couldn’t be instantiated.▶   Modules provides a names...
How we usually do this in PHPInterface ILog{    function write($message)}EventLog implements ILog{   function write($messa...
How we do this in Rubymodule Log  def write   #code  endEndclass EventLog   include Log   def Prepare   endend
Implementing Enumerable▶   From Enumerable module documentation:    The Enumerable mixin provides collection    classes wi...
Implementing Enumerableclass MyCollection   include Enumerable   def each      #yields result   endend
About coding guide lines▶   Remember the times of Hungarian    notation?        $f_amount = 100.00;        $s_string = “I ...
You. When you get someones code  with different coding guide lines.
Ruby Coding guide linesRuby syntaxes mostly dictates codingguidelines:  ▶   localVariable  ▶   @instanceVariable  ▶   @@cl...
Ruby metaprogramming▶   DRY – Don’t repeat yourself.▶   But that’s another story 
FrameworksRuby                    PHP▶   Ruby on             ▶   Symfony, Yii, Zend    Rails, Merb             …▶   Sinatr...
ToolsRuby                     PHP▶   Ruby Gems            ▶   PEAR, Composer▶   Bundler              ▶   Bash, Composer▶  ...
Testing Rocks!
Feel like a Rubier now?
Ruby tutorial 101Interactive ruby tutorial:▶ http://tryruby.org/Online course:▶ http://www.coursera.org/course/saas/▶
Books▶   Programming Ruby (Pick Axe book)By Thomas D., Fowler C., Hunt A.▶   Design Patterns In RubyBy Russ Olsen▶   Searc...
Follow the ruby side we have cookies        
Questions?   Ruby for PHP developers          By Max TitovGet examples: www.maxtitov.meGet in touch: eolexe@gmail.com     ...
Ruby for PHP developers
Upcoming SlideShare
Loading in …5
×

Ruby for PHP developers

11,106 views
10,862 views

Published on

Published in: Technology, Education
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
11,106
On SlideShare
0
From Embeds
0
Number of Embeds
3,267
Actions
Shares
0
Downloads
20
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Ruby for PHP developers

  1. 1. Ruby for PHPDevelopers By Max Titov maxtitov.me Ninja Software Operations
  2. 2. Objective: learn and compare▶ What is Ruby and where it is come from?▶ Why Ruby?▶ Ruby basics▶ Ruby ecosystem▶ Ruby specialties▶ How to get started?
  3. 3. Facts▶ First “Hello World” in 1995 (PHP 1995 too)▶ Opensource (PHP too)▶ Inspired by: Perl, Smalltalk, Lisp, Python …▶ Philosophy: Designed for programmer productivity and fun.
  4. 4. Creator"I wanted a scripting language that wasmore powerful than Perl, and more object-oriented than Python. Thats why I decidedto design my own language.” Yukihiro (Matz) Matsumoto
  5. 5. Why Ruby?▶ It’s fun!▶ It’s going to make your better.▶ And definitely it will sabotage what you believe in.
  6. 6. Similarities▶ Ruby has exception handling▶ Garbage collector▶ The is fairly large standard library▶ The are classes and access modifiers
  7. 7. Ruby is Dynamic▶ No need to declare variablesvar = “World in hell”var.class #Stringvar = 1var.class #Fixnum
  8. 8. Ruby is Strong Typed▶ Like in Java or C# there is no type juggling. You need to convert between types.a = “1”b=2a + b #TypeError: cant convert Fixnum into Stringa.to_i + b # 3
  9. 9. Everything is an Object▶ Inspired by SmallTalk▶ Unlike other programming languages that states the same, Ruby really is.
  10. 10. Everything is an Object▶ Primitive Types are an objects10.times {puts “I am sexy and I know it!”}#Output “I am sexy and I know it!”#Output “I am sexy and I know it!”#Output “I am sexy and I know it!”#Output “I am sexy and I know it!”#Output “I am sexy and I know it!”#....(10 times)…
  11. 11. Everything is an Object▶ Control structures are object methods class Fixnum < Integer def – numeric # subtracting code end end
  12. 12. Ruby is Flexible▶ Existing ruby code could be easily altered. class Numeric def toSquare self * self end end 2.toSquare# 4
  13. 13. Duck typing▶ Definition: When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck. (Wikipedia)
  14. 14. Duck typingWhat makes object an object? Answer is a: Behavior
  15. 15. So, is it a duck?Swim? YesCan Quack? YesIs it a duck?Definitely!
  16. 16. And this?Swim? YesCan Quack? Yes. Kind ofstrange, but still itmake quack like soundIs it a duck?Looks like!
  17. 17. How, about this?Swim? Badly, but yes.Can Quack? Yeah, makePlenty of sounds but, canquack also.Is it a duck?Sort of weird duck, but yes!
  18. 18. Or, probably this?Swim? YepCan quack? Canmake weird quacksounds.Is it duck?Trying very hard, soyes 
  19. 19. Duck Typing▶ So, everything that could respond to several criterias that makes us believe that it’s a duck, is a duck.
  20. 20. Duck Typing in context of Ruby▶ There is no abstract classes and interfaces.▶ There is Modules and Mixins.
  21. 21. Modules and Mixins▶ Modules define reusable pieces of code that couldn’t be instantiated.▶ Modules provides a namespace and prevent name clashes▶ Modules could be “mixin” to any class that satisfy conventions described in documentation (Should quack and swim like a duck).▶ In PHP 5.4 Traits is an equivalent to Mixins
  22. 22. How we usually do this in PHPInterface ILog{ function write($message)}EventLog implements ILog{ function write($message) { //useful code }}
  23. 23. How we do this in Rubymodule Log def write #code endEndclass EventLog include Log def Prepare endend
  24. 24. Implementing Enumerable▶ From Enumerable module documentation: The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method “each”, which yields successive members of the collection.
  25. 25. Implementing Enumerableclass MyCollection include Enumerable def each #yields result endend
  26. 26. About coding guide lines▶ Remember the times of Hungarian notation? $f_amount = 100.00; $s_string = “I am definitely a string”;▶ How many coding guide lines there? ▶ PEAR, ▶ Zend, ▶ Wordpress ▶ Your company standard
  27. 27. You. When you get someones code with different coding guide lines.
  28. 28. Ruby Coding guide linesRuby syntaxes mostly dictates codingguidelines: ▶ localVariable ▶ @instanceVariable ▶ @@classVariable ▶ $globalVariable ▶ Constant ▶ ClassName ▶ method_name
  29. 29. Ruby metaprogramming▶ DRY – Don’t repeat yourself.▶ But that’s another story 
  30. 30. FrameworksRuby PHP▶ Ruby on ▶ Symfony, Yii, Zend Rails, Merb …▶ Sinatra ▶ Sylex▶ Radiant, Mephisto ▶ WordPress, Drupal , Joomla
  31. 31. ToolsRuby PHP▶ Ruby Gems ▶ PEAR, Composer▶ Bundler ▶ Bash, Composer▶ TestUnit, minitest ▶ PHPUnit▶ Cucumber, Rspec, ▶ Behat Shoulda
  32. 32. Testing Rocks!
  33. 33. Feel like a Rubier now?
  34. 34. Ruby tutorial 101Interactive ruby tutorial:▶ http://tryruby.org/Online course:▶ http://www.coursera.org/course/saas/▶
  35. 35. Books▶ Programming Ruby (Pick Axe book)By Thomas D., Fowler C., Hunt A.▶ Design Patterns In RubyBy Russ Olsen▶ Search Google for: Learn Ruby
  36. 36. Follow the ruby side we have cookies 
  37. 37. Questions? Ruby for PHP developers By Max TitovGet examples: www.maxtitov.meGet in touch: eolexe@gmail.com Twitter: eolexe

×