Ruby is designed to make programmers happy by providing simplicity, openness, and an object-oriented yet dynamic programming experience. It aims to focus on humans rather than machines. Ruby promotes productivity through conventions that speed development and testing. Programmers enjoy coding in Ruby due to its immediate feedback and morale boost. Ruby has broad utility across web, text, and GUI applications and is platform agnostic, running on most operating systems.
4. a = "hello world"
class String
def no_vowels
self.gsub(/[aeiou]/, '')
end
end
p a.no_vowels # "hll wrld"
Openness
5. Natural Language
case year
when 1800...1900 then "19th century"
when 1900...2000 then "20th century"
else "21st century"
end
"word".include? "a"
5.times do
paint.stir!
end
color "orange blossom" do
red 224
yellow 147
blue 22
end
11. Modules, Classes, and Objects
module Authentication
def valid_api_keys
Database.retrieve_all_keys
end
def authenticated?(api_key)
valid_api_keys.include?
api_key
end
end
class PublicAPI
include Authentication
def initialize(api_key)
@api_key = api_key
end
def act
if authenticated?(@api_key)
do_a_thing
end
end
end
12. Inheritance
class PrivateAPI end
include Authentication
class PublicAPI
def initialize(id, api_key) include Authentication
@client = DB.get_client
(id) def act
@api_key = api_key if authenticated?(@api_key)
end do_a_thing
end
def valid_api_keys end
@client.api_keys end
end
class NewAPI < PublicAPI
def act def act
if authenticated? if authenticated?(@api_key)
(@api_key) do_a_new_thing
@client.do_a_thing end
end end
end end
19. First-‐class FuncDons
def is_prime?(x)
is_prime = proc do |n, m|
if m > (n / 2)
true
elsif n % m == 0
false
else
is_prime.call(n, m + 1)
end
end
is_prime.call(x, 2) if x >= 2
end
(1..23).select { |n| is_prime?(n) }
# => [2, 3, 5, 7, 11, 13, 17, 19, 23]
21. Metaprogramming
module Accessors
def access(var)
define_method(var) do
instance_variable_get("@#{var}")
end
define_method("#{var}=") do |val|
instance_variable_set("@#{var}",
val)
end
end
end
22. Metaprogramming
class Monster
extend Accessors
access :damage
def initialize(damage)
@damage = damage
end
end
wampa = Monster.new("2d6")
wampa.damage # => "2d6"
wampa.damage = "1d12"
27. Web deployment
set :application, 'listy'
set :repository, "git@github.com:viget/listyapp.git"
set :scm, 'git'
role :web, "listyapp.com"
role :app, "listyapp.com"
role :db, "listyapp.com", :primary => true
set :user, "listy"
set :deploy_to, "/home/listy/rails"
28. RubyGems
Standard package
management tool
More like apt than CPAN
Included with Ruby 1.9
29. Open Source
The Ruby License is much
like the MIT License.
Most Ruby gems are under
the Ruby license or MIT
License.
GitHub is the hub of most
Ruby OS activity.
33. TesDng
Rails was the first
framework I used that
came with testing built in.
Community has exploded
in the last few years with
testing tools.
It’s rare I see a project
without tests.
34. ConvenDon over ConfiguraDon
“The three chief virtues of a programmer are:
Laziness, Impatience and Hubris.”
– Larry Wall, who is not a Ruby programmer
35. Version Control
Everyone should use version control, so this
isn’t really a value.
But Ruby programmers are fanatics for their
VCS.
Git is the VCS of choice.
Being distributed, it allows for easy public forks
of projects, which has helped OS in Ruby.
36. Sharing
Ruby programmers have been
chastised as self-promoters. I
don’t see that as a bad thing.
We share everything: open
source code, discoveries, tips
and tricks.
Talk, talk, talk
Blog, blog, blog
38. Why Ruby Was Right For Us
(and Might Be Right For You)
39. O"en people, especially computer engineers,
focus on the machines. They think, "By doing
this, the machine will run faster. By doing this,
the machine will run more effec>vely. ..." They
are focusing on machines. But in fact we need
to focus on humans, on how humans care
about doing programming or opera>ng the
applica>on of the machines.
– Matz
TranslaDon: Ruby is not so fast.
40. ProducDvity
Conventions and dynamism
speed development.
There are ridiculous quotes
about “3-10x.”
Personal observation: as a
project goes on, it doesn’t get
any harder, unlike other
languages.
Will testing slow you down?
41. Morale
Anecdotally: people like to
program in Ruby.
Productive people are
happier.
Seeing instant results is
very rewarding.
42. Broad UDlity
Text processing
Cross-platform GUI development: Monkeybars,
Limelight, and Shoes
Server configuration management: Chef, Puppet, and
Sprinkle
Web servers: Mongrel, Unicorn, and Thin
Testing other languages
and anything else that isn’t matheletic
43. PlaYorm AgnosDc
MRI runs on Windows, OS X, Linux, and most
other Unixes.
JRuby runs anywhere Java will run.
IronRuby is going to make .NET awesome.
Passenger works with Apache.
But you can proxy through or use FastCGI from
any web server, even IIS.