SlideShare a Scribd company logo
10 THINGS I LEARNED WHEN 
SWITCHING TO RUBY/RAILS 
DANIEL SMITH, @DANIELSMITH 
EVERFI
WHO AM I & 
WHY AM I HERE 
STORY TIME!
I APOLOGIZE FOR: 
IMAGES, FONTS, COLORS, LAYOUT ETC. 
…AND BAD JOKES
PROGRAMMING 
3-WAY 
THE BATTLE BETWEEN GOOD 
AND EVIL?!
1. RUBY VS. RAILS 
Ruby != Rails 
Command Ruby Rails 
s 
= 
“1-­‐1-­‐2012” 
#=> 
“1-­‐1-­‐2012” 
#=> 
“1-­‐1-­‐2012” 
s.reverse 
#=> 
“2101-­‐1-­‐1” 
#=> 
“2101-­‐1-­‐1” 
s.to_date 
#=> 
NoMethodError 
#=> 
Sun, 
01 
Jan 
2012 
Common language/Framework issue: 
Objective-C + Cocoa 
C# + .NET 
A lot of people don’t know the difference or what is part of 
what.
DATING YOUR 
ORM 
EVERYONE IS DOING IT!
2. KNOW YOUR ORM 
Not understanding ActiveRecord is like not knowing your best 
friends birthday. 
Spend time learning the relationships and constraints, etc. 
Understand migration paths and how they work. 
What does the model have to do with the database? 
How does a model influence other pieces?
THERE ARE 
OBJECTS 
EVERYWHERE 
THEY’RE IN MY RACCOON 
WOUNDS…
3. EVERYTHING IS AN OBJECT 
class and module are in fact OBJECTS 
What does this example return? 
class 
SomeClass; 
end 
It’s just code being evaluated. 
What about this? Is this ok? 
3.times 
do 
class 
SomeClass 
‘My 
Class’ 
end 
end
DHH 
COMMANDS 
YOU! 
AT LEAST I FEEL LIKE HE IS 
JUDGING ME…
4. THE RUBY WAY/RAILS WAY 
Don’t port your old habits over - learn new ones. 
Syntax 
Ruby should read like English (well sort of) 
White space matters…semicolons not so much 
USE BLOCKS 
Odd numbers: (1..100).step(2) 
Conditionals: do 
something 
if 
something?
CREEP 
NOT THE RADIOHEAD HIT 
SONG
5. SCOPE CREEP IS REAL 
Understanding variable scope can be important 
@someVar VS. someVar 
Making good choices in passing variables to view layer 
Partials <% 
render 
somevar: 
@someThing 
%> 
Avoid spaghetti code! 
Avoid shadow variables 
people 
= 
[‘Andrew’, 
‘Bill’, 
‘Calvin’] 
person 
= 
‘Daniel’ 
people.each 
do 
|person| 
puts 
“It’s 
#{person}’s 
turn!” 
end
KEEPING IT 
OPEN 
“MONKEY PATCHING” IS 
AWESOME
6. THROWING POO (MONKEYPATCHING) 
“Monkey patching is awesome as long as you are the one doing 
it” - @derekgallo 
I love open classes!!! Be careful! 
UNIT TEST!!! 
Understand what your gems monkey patch 
Using open classes for organization - string.rb in ActiveSupport
STRING.RB require 
'active_support/core_ext/string/conversions' 
require 
'active_support/core_ext/string/filters' 
require 
'active_support/core_ext/string/multibyte' 
require 
'active_support/core_ext/string/starts_ends_with' 
require 
'active_support/core_ext/string/inflections' 
require 
'active_support/core_ext/string/access' 
require 
'active_support/core_ext/string/xchar' 
require 
'active_support/core_ext/string/behavior' 
require 
'active_support/core_ext/string/interpolation' 
require 
'active_support/core_ext/string/output_safety' 
require 
'active_support/core_ext/string/exclude' 
require 
'active_support/core_ext/string/encoding' 
require 
'active_support/core_ext/string/strip' 
require 
'active_support/core_ext/string/inquiry' 
All of which start with: class 
String
SHARING IS 
CARING
7. WHAT DOES THAT GEM DO?! 
Lets play a game and guess what each of these do! 
gem oink 
gem dalli 
gem wolverine 
gem kaminari
7. GEM ABUSE 
Ask yourself these questions when adding a gem: 
What does it really do? 
Do we really need it? Do we have another gem that already 
does this? 
Is it well maintained? (check the repo!) 
Is there a better alternative? 
Think about what it might change about your application.
CONSOLE LOVE! 
I DIDN’T HAVE THIS BEFORE
8. IRB AND THE RAILS CONSOLE 
Stopped using (for the most part) a database tool 
Run most lookups/inserts in a console 
Makes sure you are using model’s logic 
Helps debug code 
Quickly test snippets (often, even when writing this)
I <3 λ 
BLOCKS, PROCS, LAMBDAS 
OH MY!
9. BLOCKS RUN THE WORLD 
Lambdas have a return - procs do not. 
Return differences 
Lambda returns from itself (like an anonymous function) 
Proc returns from its “parent” method 
def 
some_proc 
myProc 
= 
Proc.new 
{ 
return 
} 
myProc.call 
puts 
“After 
the 
proc” 
end 
! 
some_proc 
def 
some_lambda 
myLbda 
= 
lambda 
{ 
return 
} 
myLbda.call 
puts 
“After 
the 
lambda” 
end 
! 
some_lambda
DEBUGGING THE 
UNKNOWN
10. DEBUGGING THE UNKNOWN 
NoMethodError, method_missing() to the rescue 
define_method is awesome 
Dynamic methods/attributes in ActiveRecord 
Attributes are defined using #method_missing() SHOCKER 
Rails 4.0 kills off find_by* :-) 
Routing methods (use them) 
_url 
_path
QUESTIONS?
ADDITIONAL INFO 
Daniel Smith 
Senior Software Architect - EverFi 
@danielrsmith - Twitter 
http://danielrs.com - The Internets 
RubyMine 
Dash 
Alfred 
awesome_print 
zsh 
oh_my_zsh 
HomeBrew 
Atom.io 
CodeSchool 
HoneyBadger 
NewRelic 
…

More Related Content

Similar to ORUG - Sept 2014 - Lesson When Learning Ruby/Rails (20)

PPT
WorkinOnTheRailsRoad
webuploader
 
PPT
Rapid Application Development using Ruby on Rails
Simobo
 
PDF
Rails - getting started
True North
 
KEY
Rails traps
Reuven Lerner
 
PPTX
Why Ruby?
IT Weekend
 
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
PPTX
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
PPT
Ruby On Rails Tutorial
sunniboy
 
PPTX
Ruby on rails for beginers
shanmukhareddy dasi
 
PDF
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
PPT
Ruby On Rails
Gautam Rege
 
KEY
Ruby on Rails Training - Module 1
Mark Menard
 
PDF
Ruby Rails Web Development
Sonia Simi
 
PPT
Ruby On Rails Introduction
Gustavo Andres Brey
 
PDF
Ruby on rails RAD
Alina Danila
 
PPT
Introduction To Rails
Eric Gruber
 
PPT
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
PDF
Workin On The Rails Road
RubyOnRails_dude
 
PDF
Ruby On Rails
Balint Erdi
 
KEY
Ruby On Rails Overview
jonkinney
 
WorkinOnTheRailsRoad
webuploader
 
Rapid Application Development using Ruby on Rails
Simobo
 
Rails - getting started
True North
 
Rails traps
Reuven Lerner
 
Why Ruby?
IT Weekend
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
Ruby On Rails Tutorial
sunniboy
 
Ruby on rails for beginers
shanmukhareddy dasi
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Ruby On Rails
Gautam Rege
 
Ruby on Rails Training - Module 1
Mark Menard
 
Ruby Rails Web Development
Sonia Simi
 
Ruby On Rails Introduction
Gustavo Andres Brey
 
Ruby on rails RAD
Alina Danila
 
Introduction To Rails
Eric Gruber
 
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
Workin On The Rails Road
RubyOnRails_dude
 
Ruby On Rails
Balint Erdi
 
Ruby On Rails Overview
jonkinney
 

Recently uploaded (20)

PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Ad

ORUG - Sept 2014 - Lesson When Learning Ruby/Rails

  • 1. 10 THINGS I LEARNED WHEN SWITCHING TO RUBY/RAILS DANIEL SMITH, @DANIELSMITH EVERFI
  • 2. WHO AM I & WHY AM I HERE STORY TIME!
  • 3. I APOLOGIZE FOR: IMAGES, FONTS, COLORS, LAYOUT ETC. …AND BAD JOKES
  • 4. PROGRAMMING 3-WAY THE BATTLE BETWEEN GOOD AND EVIL?!
  • 5. 1. RUBY VS. RAILS Ruby != Rails Command Ruby Rails s = “1-­‐1-­‐2012” #=> “1-­‐1-­‐2012” #=> “1-­‐1-­‐2012” s.reverse #=> “2101-­‐1-­‐1” #=> “2101-­‐1-­‐1” s.to_date #=> NoMethodError #=> Sun, 01 Jan 2012 Common language/Framework issue: Objective-C + Cocoa C# + .NET A lot of people don’t know the difference or what is part of what.
  • 6. DATING YOUR ORM EVERYONE IS DOING IT!
  • 7. 2. KNOW YOUR ORM Not understanding ActiveRecord is like not knowing your best friends birthday. Spend time learning the relationships and constraints, etc. Understand migration paths and how they work. What does the model have to do with the database? How does a model influence other pieces?
  • 8. THERE ARE OBJECTS EVERYWHERE THEY’RE IN MY RACCOON WOUNDS…
  • 9. 3. EVERYTHING IS AN OBJECT class and module are in fact OBJECTS What does this example return? class SomeClass; end It’s just code being evaluated. What about this? Is this ok? 3.times do class SomeClass ‘My Class’ end end
  • 10. DHH COMMANDS YOU! AT LEAST I FEEL LIKE HE IS JUDGING ME…
  • 11. 4. THE RUBY WAY/RAILS WAY Don’t port your old habits over - learn new ones. Syntax Ruby should read like English (well sort of) White space matters…semicolons not so much USE BLOCKS Odd numbers: (1..100).step(2) Conditionals: do something if something?
  • 12. CREEP NOT THE RADIOHEAD HIT SONG
  • 13. 5. SCOPE CREEP IS REAL Understanding variable scope can be important @someVar VS. someVar Making good choices in passing variables to view layer Partials <% render somevar: @someThing %> Avoid spaghetti code! Avoid shadow variables people = [‘Andrew’, ‘Bill’, ‘Calvin’] person = ‘Daniel’ people.each do |person| puts “It’s #{person}’s turn!” end
  • 14. KEEPING IT OPEN “MONKEY PATCHING” IS AWESOME
  • 15. 6. THROWING POO (MONKEYPATCHING) “Monkey patching is awesome as long as you are the one doing it” - @derekgallo I love open classes!!! Be careful! UNIT TEST!!! Understand what your gems monkey patch Using open classes for organization - string.rb in ActiveSupport
  • 16. STRING.RB require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/filters' require 'active_support/core_ext/string/multibyte' require 'active_support/core_ext/string/starts_ends_with' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/access' require 'active_support/core_ext/string/xchar' require 'active_support/core_ext/string/behavior' require 'active_support/core_ext/string/interpolation' require 'active_support/core_ext/string/output_safety' require 'active_support/core_ext/string/exclude' require 'active_support/core_ext/string/encoding' require 'active_support/core_ext/string/strip' require 'active_support/core_ext/string/inquiry' All of which start with: class String
  • 18. 7. WHAT DOES THAT GEM DO?! Lets play a game and guess what each of these do! gem oink gem dalli gem wolverine gem kaminari
  • 19. 7. GEM ABUSE Ask yourself these questions when adding a gem: What does it really do? Do we really need it? Do we have another gem that already does this? Is it well maintained? (check the repo!) Is there a better alternative? Think about what it might change about your application.
  • 20. CONSOLE LOVE! I DIDN’T HAVE THIS BEFORE
  • 21. 8. IRB AND THE RAILS CONSOLE Stopped using (for the most part) a database tool Run most lookups/inserts in a console Makes sure you are using model’s logic Helps debug code Quickly test snippets (often, even when writing this)
  • 22. I <3 λ BLOCKS, PROCS, LAMBDAS OH MY!
  • 23. 9. BLOCKS RUN THE WORLD Lambdas have a return - procs do not. Return differences Lambda returns from itself (like an anonymous function) Proc returns from its “parent” method def some_proc myProc = Proc.new { return } myProc.call puts “After the proc” end ! some_proc def some_lambda myLbda = lambda { return } myLbda.call puts “After the lambda” end ! some_lambda
  • 25. 10. DEBUGGING THE UNKNOWN NoMethodError, method_missing() to the rescue define_method is awesome Dynamic methods/attributes in ActiveRecord Attributes are defined using #method_missing() SHOCKER Rails 4.0 kills off find_by* :-) Routing methods (use them) _url _path
  • 27. ADDITIONAL INFO Daniel Smith Senior Software Architect - EverFi @danielrsmith - Twitter http://danielrs.com - The Internets RubyMine Dash Alfred awesome_print zsh oh_my_zsh HomeBrew Atom.io CodeSchool HoneyBadger NewRelic …