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
Rails Magic Exposed
Search
Jesse Wolgamott
August 11, 2012
Programming
2
2.3k
Rails Magic Exposed
The Ruby that powers Rails.. LoneStarRubyConf 2012
Jesse Wolgamott
August 11, 2012
Tweet
Share
More Decks by Jesse Wolgamott
See All by Jesse Wolgamott
React vs React-Native
jwo
0
99
What is an API
jwo
0
180
DIY Rails Authentication
jwo
0
180
ActionCable - For Not Another Chat App
jwo
3
1.4k
SlackBot.rb - Create You a Slack Bot
jwo
1
1.3k
react-rails: an isomorphic match made in heaven
jwo
0
1.2k
Docker - next big thing
jwo
0
860
Ruby 2.1 Overview
jwo
0
870
Rails 4: Appetizers
jwo
1
880
Other Decks in Programming
See All in Programming
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
370
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
360
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
210
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
120
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
800
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
770
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
120
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
110
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
130
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
190
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
400
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
74
9.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Language of Interfaces
destraynor
155
24k
Docker and Python
trallard
42
3.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Optimising Largest Contentful Paint
csswizardry
33
3k
For a Future-Friendly Web
brad_frost
175
9.5k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Documentation Writing (for coders)
carmenintech
67
4.5k
Designing Experiences People Love
moore
139
23k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Music & Morning Musume
bryan
46
6.2k
Transcript
Rails magic Saturday, August 11, 12
EPFT NBHJD FYJTU Saturday, August 11, 12
MFU`TBTL 4$*&/$& Saturday, August 11, 12
(PPHMF 3FTVMUT Saturday, August 11, 12
Framework Magic Total php (1994) 132000 2.527E+10 java (1995) 45900
960000000 .net (2002) 4400 250000000 django (2004) 9370 44300000 rails (2005) 7040 20300000 Saturday, August 11, 12
.BHJD3BUJP w1)1 w+BWB w/&5 Saturday, August 11, 12
.BHJD3BUJP w%KBOHP w3BJMT Saturday, August 11, 12
0 1 2 3 4 php (1994) java (1995) .net
(2002) django (2004) rails (2005) 0.052 0.478 0.176 2.115 3.468 Magic over Time Frequency / 10000 Saturday, August 11, 12
0 1 2 3 4 php (1994) java (1995) .net
(2002) django (2004) rails (2005) Node 0.052 0.478 0.176 2.115 3.468 2.031 A Step Back Saturday, August 11, 12
0 100 200 300 400 php (1994) .net (2002) rails
(2005) Meteor.js 0.052 0.478 0.176 2.115 3.468 2.031 345.810 MAGIC of Meteor Saturday, August 11, 12
l"OZTVGpDJFOUMZ BEWBODFE UFDIOPMPHZJT JOEJTUJOHVJTIBCMF GSPNNBHJDz "SUIVS$$MBSL Saturday, August 11, 12
dynamic finders Saturday, August 11, 12
id = params[:customer_id] YourModel.find_by_customer_id id Saturday, August 11, 12
def method_missing(method_id, *arguments) if match = /find_(all_by|by)_([_a-zA-Z]\w*)/. match(method_id.to_s) # find...
elsif match = /find_or_create_by_([_a-zA-Z] \w*)/. match(method_id.to_s) # find_or_create... else super end end Saturday, August 11, 12
magic columns Saturday, August 11, 12
created_at and updated_at counter_caches type Saturday, August 11, 12
def apply_it(items) items.map do |item| item.apply! if item.respond_to? (:apply!) end
end Saturday, August 11, 12
Active Record definition Saturday, August 11, 12
class User < ActiveRecord::Base has_many :posts has_many :comments, through: :posts
validates_presence_of :email end Saturday, August 11, 12
class SuperWo 20.times {|i| puts "This is the #{i}”} def
wat! puts "hi" end end SuperWo.new.wat! Try it out: http://rubyfiddle.com/riddles/a63dd Saturday, August 11, 12
auto loading Saturday, August 11, 12
Dir.glob('./app/models/*').each do |file| require file end require_relative 'db/setup' require_relative 'models/page'
require_relative 'models/book' Saturday, August 11, 12
CFDBVTF "DUJWF4VQQPSU %FQFOEFODJFT VSM IUUQSLIJN DPEFSFMPBEJOH Saturday, August 11, 12
# Extremely simple autoloading implementation class Module alias const_missing_without_autoloading const_missing
def const_missing(const) path = “./#{name.gsub('::', '/')}/#{const}" path.gsub!(/([a-z\d])([A-Z])/,'\1_\2') require path.downcase const_defined?(const) ? const_get(const) : super rescue LoadError => error warn(error.message) super end end Saturday, August 11, 12
"VUP-PBEJO"DUJPO HJUIVCKXP DMPBLFEUZSJPO Saturday, August 11, 12
4PNVDINPSF Saturday, August 11, 12
class Foo @@foo ||= 42 puts @@foo # 42 end
# reload... class Foo @@foo ||= 23 puts @@foo # 42 end Saturday, August 11, 12
# reload... Object.send(:remove_const, :Foo) class Foo @@foo ||= 23 puts
@@foo # 23 end Saturday, August 11, 12
custom ruby Saturday, August 11, 12
NPOLFZQBUDIJOH Saturday, August 11, 12
numbers = (1..100).to_a numbers.first numbers.last numbers.forty_two Saturday, August 11, 12
def forty_two self[41] end "MTPLOPXOBTBDDFTTJOHUIF SFEEJU Saturday, August 11, 12
class Enumerable def standard_dev Math.sqrt(sample_variance) end def sample_variance mean =
sum.to_f / size.to_f sum{|i| (i-mean)**2} / size end end Saturday, August 11, 12
review Saturday, August 11, 12
EZOBNJD@pOEFST NFUIPE@NJTTJOH Saturday, August 11, 12
NBHJD@DPMVNOT SFTQPOE@UP Saturday, August 11, 12
BS@EFpOJUJPOT DPNQJMF@UJNF@DPEF Saturday, August 11, 12
BVUP@MPBEJOH DPOTU@NJTTJOH Saturday, August 11, 12
NPOLFZ@QBUDIJOH PQFO@DMBTTFT Saturday, August 11, 12
@@jwo ruby off rails Saturday, August 11, 12