Slide 1

Slide 1 text

RUBY A PROGRAMMER’S BEST FRIEND

Slide 2

Slide 2 text

Background

Slide 3

Slide 3 text

Yukihiro “Matz” Matsumoto

Slide 4

Slide 4 text

I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. at is the primary purpose of Ruby language.” “

Slide 5

Slide 5 text

- Programmer happiness - Principle of least astonishment - Human readable - Beautiful syntax Principles

Slide 6

Slide 6 text

- RubyGems, Bundler & Rake - Multiple implementations (MRI, JRuby, Rubinius, mruby, MacRuby, Topaz, …) - Solid Standard Library Ecosystem

Slide 7

Slide 7 text

- MINASWAN - Self re ective - Open - Quirky Community

Slide 8

Slide 8 text

The Language A Sales Pitch

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Object–oriented 1

Slide 11

Slide 11 text

5.times { print "We love Ruby" }

Slide 12

Slide 12 text

class Animal def eat(food) puts "Animal eating" end end my_animal = Animal.new animal.eat # => "Animal eating"

Slide 13

Slide 13 text

class Dog < Animal def eat(food) puts "Dog eating" super end end

Slide 14

Slide 14 text

module Stomach def digest(food) # ... end end

Slide 15

Slide 15 text

class Dog < Animal include Stomach end my_dog = Dog.new dog.digest

Slide 16

Slide 16 text

-199.abs # => 199 "Foobar".split("").uniq.sort.join # => "abFor" nil.class # => "NilClass"

Slide 17

Slide 17 text

Dynamically typed Duck–typing 2

Slide 18

Slide 18 text

if dog.is_a? Animal dog.eat end dog.eat if dog.respond_to?(:eat)

Slide 19

Slide 19 text

Monkey–patching (Duck–punching) 3

Slide 20

Slide 20 text

… if it walks like a duck and talks like a duck, it’s a duck, right? So if this duck is not giving you the noise that you want, you’ve got to just punch that duck until it returns what you expect.” “

Slide 21

Slide 21 text

class String def yell "#{self.upcase}!" end end "hello".yell # => "HELLO!"

Slide 22

Slide 22 text

Meta–programming 4

Slide 23

Slide 23 text

class Greeter def method_missing(name, *args) name = name.to_s if name =~ /^hello_/ puts "Hello, #{name.gsub(/^hello_/, '')}!" else super end end end Greeter.new.hello_john # => "Hello, john!"

Slide 24

Slide 24 text

Blocks & Lambdas 5

Slide 25

Slide 25 text

[1, 2, 3].map { |i| i ** 2 } # => [1, 4, 9]

Slide 26

Slide 26 text

def greet(&block) # ... greeting = yield("John") # ... end greet do |name| "Hello, #{name}!" end

Slide 27

Slide 27 text

A word on speed

Slide 28

Slide 28 text

Ruby on Rails An (even shorter) sales pitch

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

- Open Source Web Framework - MVC - Convention over Con guration - DRY - Opinionated Principles

Slide 31

Slide 31 text

- Generators - ORM - Restful routing - Included webserver Features

Slide 32

Slide 32 text

$ gem install rails $ rails new blog $ cd blog $ rails generate scaffold post title content:text $ rake db:migrate $ rails server

Slide 33

Slide 33 text

author = Author.find_by :name => "John" author.posts.first.title

Slide 34

Slide 34 text

Book.where(:title => 'Tale of Two Cities') .first_or_create

Slide 35

Slide 35 text

class Account < ActiveRecord::Base # Returns all accounts with unread messages. def self.with_unread_messages joins(:messages).merge(Message.unread) end end

Slide 36

Slide 36 text

No content