Reasons To Love Ruby

1,685 views

Published on

A general introduction to the Ruby language and ecosystem from a .NET Developer's perspective.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,685
On SlideShare
0
From Embeds
0
Number of Embeds
97
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Reasons To Love Ruby

  1. 1. a bunch of reasons to love ruby<br />
  2. 2. class Ben &lt; Personis_a :mvp, :scrummaster, :aspinsider def initialize @book = “ASP.NET MVC in Action” @twitter = “subdigital” @blog= “http://flux88.com” @iphone_app= “Pocket Tabs” end ...end<br />
  3. 3. def self.expert? falseend<br />
  4. 4. Meet Ruby<br />puts“hello world”hello world<br />puts“hello world”.reversedlrowolleh<br />puts“hello world”[0..5] hello<br />
  5. 5. Ruby Variables<br />num = 323<br />message = “Hey there”<br />stuff = [1, “foo”, true]<br />
  6. 6. Ruby Loops<br />[“cat”, “dog”, “giraffe”].each do |s|<br /> puts s<br />end<br />[“cat”, “dog”, “giraffe”].each { |s| puts s }<br />
  7. 7. Working with Arrays<br />animals = [“zebra”, “donkey”, “lemur”]<br />animals.sort[“donkey”, “lemur”, “zebra”]<br /> # original array is untouched<br />animals.sort!<br /># original array is modified!<br />animals.delete“zebra” [“donkey”, “lemur”]<br />
  8. 8. Ruby has Less Ceremony<br />//C#<br />Dictionary&lt;string, object&gt; hash = new Dictionary&lt;string, object&gt;();<br />#ruby<br />hash = {}<br />#optional semicolons & parentheses<br />add(5, 6); is the same as add 5, 6<br />
  9. 9. You Can Extend Existing classes<br />5.days.from_now<br />
  10. 10. Ruby is Terse, yet Readable<br />3.times { print “Ho ” } =&gt; Ho Ho Ho<br />approve_credit unless account.deliquent?<br />send_email if email_enabled?<br />
  11. 11. Regex is a 1st class citizen<br />[“red”, “blue”, “green”].grep /u/ blue<br />“The Times They are a-Changin’”.gsub /s/, “.”<br />The.Times.They.are.a-Changin’<br />
  12. 12. Everything is an Object<br />42.class FixNum<br />42.2.class.superclass  Integer<br />42.class.superclass.superclass  Numeric<br />42.class.superclass.superclass.superclass  Object<br />No, really… everything is an object<br />puts customer.name unless customer.nil?<br />nil.classNilClass<br />nil.class.superclass Object<br />
  13. 13. RubyGems<br />gem installhpricot<br />
  14. 14. Speaking of hpricot…<br />require ‘rubygems’<br />require ‘hpricot’<br />require ‘open-uri’<br />uri = open(“http://whatsit.org”)<br />doc = Hpricot(uri)<br />(doc/&quot;p/a/img&quot;).each do |img|<br /> puts img.attributes[&apos;class&apos;]<br />end<br />
  15. 15. Rake<br />task :codeGen do<br /> # do the code generation<br />end<br />task :compile =&gt; :codeGen do<br /> #do the compilation<br />end<br />task :dataLoad =&gt; :codeGen do<br /> # load the test data<br />end<br />task :test =&gt; [:compile, :dataLoad] do<br /> # run the tests<br />end<br />
  16. 16. RSpec<br /># bowling_spec.rb<br />require &apos;bowling&apos;<br />describe Bowling do<br /> it &quot;should score 0 for gutter game&quot; do<br /> bowling = Bowling.new<br /> 20.times { bowling.hit 0 }<br />bowling.score.should == 0<br /> end<br />end<br />
  17. 17. …and now the elephant in the room<br />rails<br />
  18. 18. Rails is the bee’s knees because…<br />convention <br />configuration<br />
  19. 19. Rails is the bee’s knees because…<br />it has<br />ActiveRecord<br />
  20. 20. Rails is the bee’s knees because…<br />it has<br />Migrations<br />
  21. 21. Rails is the bee’s knees because…<br />it has the<br />Console<br />
  22. 22. Rails is the bee’s knees because…<br />scaffolding<br />
  23. 23. Rails is the bee’s knees because…<br />Logging is built-in<br />
  24. 24. Rails is the bee’s knees because…<br />Tests come out of the box<br />
  25. 25. Rails is the bee’s knees because…<br />There is ONE WAY<br />
  26. 26. What else?<br />heroku<br />
  27. 27. What else?<br />IronRuby<br />
  28. 28. thank_you<br />

×