Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby by Example
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
James Hughes
June 22, 2012
Programming
590
7
Share
Ruby by Example
James Hughes
June 22, 2012
More Decks by James Hughes
See All by James Hughes
Functional Programming with Clojure
kouphax
1
150
Tyrannosaurus Rx
kouphax
0
130
React
kouphax
2
740
Play for (Java|Scala)
kouphax
0
150
Devops: A Case Study
kouphax
0
97
Scala for C# Developers
kouphax
5
2.7k
Dropwizard - Production Ready Web Services
kouphax
3
1.7k
Scala for Fun & Profit
kouphax
4
650
What Agile Means To Me
kouphax
0
170
Other Decks in Programming
See All in Programming
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
180
forteeの改修から振り返るPHPerKaigi 2026
muno92
PRO
3
270
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
200
PHPで TLSのプロトコルを実装してみるをもう一度しゃべりたい
higaki_program
0
190
Feature Toggle は捨てやすく使おう
gennei
0
560
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
240
ルールルルルルRubyの中身の予備知識 ── RubyKaigiの前に予習しなイカ?
ydah
1
140
KagglerがMixSeekを触ってみた
morim
0
370
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
460
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
920
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
580
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
3
520
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
99
A better future with KSS
kneath
240
18k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
360
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
240
The browser strikes back
jonoalderson
0
940
Writing Fast Ruby
sferik
630
63k
How to make the Groovebox
asonas
2
2.1k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
330
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
RUBY BY EXAMPLE
Ruby is... interpreted object oriented dynamic
Ruby is... productive intuitive popular
VARIABLES & TYPES
Before we begin... a.+(b) a.is_valid? a.decrement!
$counter @@counter @counter counter Global Class Instance Local
‘hello’ ‘’‘hello’’’ %q{hello} String Herestring Perl-inspired
a = ‘James’ b = “Hello #{a}” puts b =>
“Hello James”
:hello Symbol
puts <<DOC This is a "heredoc" Multi-line String DOC
[1,2,3] {:a=>1, :b=>2} {a: 1, b: 2} 0..10 Array Hash
(1.8) Hash (1.9) Ranges
METHODS
def greet(name) “Hello, #{name}” end greet “James”
def greet(name=“World”) “Hello, #{name}” end greet “James” greet
CONTROL FLOW
if rating >= 4 puts "great" elsif rating == 3
puts "alright" else puts "sucks" end
unless rating == 5 puts “Try harder” end
puts “Try harder” unless rating == 5 puts “Seriously” if
rating == 1
case rating when 4..5 puts "great" when 3 puts "alright"
else puts "sucks" end
while !le.has_more_lines? puts !le.next_line end puts !le.next_line while !le.has_more_lines?
until !le.end_of_!le? puts !le.next_line end puts !le.next_line until !le.end_of_!le?
for i in 0...!le.line_count puts !le.lines[i] end
BLOCKS
[1,2,3,4].each do |i| puts i end
array.each(&block)
printer = Proc.new do |i| puts i end [1,2,3,4].each &printer
printer = lambda { |i| puts i }
def loggerWrapper puts "Executing Method" yield puts "Done Executing" end
loggerWrapper { puts "Weeee!" }
COLLECTIONS
Array/Enumerable Operations 109 Hash Operations 50
[1,2,3,4,5].map { |i| i +1} [1,2,3,4,5].reduce { |i, j| i
+ j } ({a: '1'}).merge({b: '2'})
CLASSES
class Person def initialize(name, age) @name,@age = name,age end end
person = Person.new("James", 32)
class Person attr_accessor :name attr_accessor :age ... end p =
Person.new("James", 32) puts p.name, p.age
class Person ... end class Hero < Person attr_accessor :powers
end p = Hero.new("James", 32) p.powers = [“Flying”]
MODULES & MIXINS
module StrUtils def self.salt(pass, slt) “#{pass}#{salt}” end def salt(slt) StrUtils::salt(@value,
slt) end end
StrUtils::salt("123", "456")
class Password include Utils def initialize(value) @value = value end
end Password.new("test").salt
TOOLS OF THE TRADE
irb Interactive shell ruby Ruby interpreter gem Library manager rake
Build tool rails Web framework
RUBY BY EXAMPLE