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