+ All Categories
Home > Technology > Reasons To Love Ruby

Reasons To Love Ruby

Date post: 31-May-2015
Category:
Upload: ben-scheirman
View: 1,447 times
Download: 2 times
Share this document with a friend
Description:
A general introduction to the Ruby language and ecosystem from a .NET Developer's perspective.
Popular Tags:
28
a bunch of reasons to love ruby
Transcript
Page 1: Reasons To Love Ruby

a bunch of reasons to love ruby

Page 2: Reasons To Love Ruby

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

def self.expert?false

end

Page 4: Reasons To Love Ruby

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

Ruby Variables

num = 323

message = “Hey there”

stuff = [1, “foo”, true]

Page 6: Reasons To Love Ruby

Ruby Loops

[“cat”, “dog”, “giraffe”].each do |s|puts s

end

[“cat”, “dog”, “giraffe”].each { |s| puts s }

Page 7: Reasons To Love Ruby

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

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

You Can Extend Existing classes

5.days.from_now

Page 10: Reasons To Love Ruby

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

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

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

RubyGems

gem install hpricot

Page 14: Reasons To Love Ruby

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

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

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

…and now the elephant in the room

rails

Page 18: Reasons To Love Ruby

Rails is the bee’s knees because…

convention

configuration

Page 19: Reasons To Love Ruby

Rails is the bee’s knees because…

it hasActiveRecord

Page 20: Reasons To Love Ruby

Rails is the bee’s knees because…

it hasMigrations

Page 21: Reasons To Love Ruby

Rails is the bee’s knees because…

it has theConsole

Page 22: Reasons To Love Ruby

Rails is the bee’s knees because…

scaffolding

Page 23: Reasons To Love Ruby

Rails is the bee’s knees because…

Logging is built-in

Page 24: Reasons To Love Ruby

Rails is the bee’s knees because…

Tests come out of the box

Page 25: Reasons To Love Ruby

Rails is the bee’s knees because…

There is ONE WAY

Page 26: Reasons To Love Ruby

What else?

heroku

Page 27: Reasons To Love Ruby

What else?

IronRuby

Page 28: Reasons To Love Ruby

thank_you


Recommended