SlideShare a Scribd company logo
Gotchas and Stack
Traces in Ruby
OmbuLabs, September 2015
#1: Whitespace
def method(arg1, arg2)
end
method 1, 2 # OK
method(1, 2) # OK
method (1, 2) # Error!
SyntaxError: (irb):24: syntax error, unexpected ',',
expecting ‘)'
from (irb):7:in `method'
#1: Whitespace
def method
42
end
num = 21
method/num # OK
method / num # OK
method/ num # OK
method /num # Error!
ArgumentError: wrong number of arguments (1 for
0)
from (irb):7:in `method'
#2: True & False
[].any? => false
[1].any? => true
[:foo, :bar].any => true
[false].any? => false
[nil].any? => false
[false, nil].any? => false
[false, true].any? => true
`any?` is actually “Are any elements truthy?”
#3: Constants (not)
FOO = 5
=> 5
FOO = 7
(irb):3: warning: already initialized constant FOO
=> 7
FOO
=> 7
Constants can be reassigned, Ruby
will just throw a warning and let you
do it anyway.
def foo
0/0
end
def bar
foo
end
def baz
bar
end
baz
➜ ombushop git:(develop) ✗ ruby test.rb
test.rb:2:in `/': divided by 0 (ZeroDivisionError)
from test.rb:2:in `foo'
from test.rb:6:in `bar'
from test.rb:10:in `baz'
from test.rb:13:in `<main>'
def foo
my_correctly_spelled_variable = "hey!"
puts my_incorrectly_spelled_variable
end
def bar
foo
end
def baz
bar
end
baz
➜ ombushop git:(develop) ✗ ruby test.rb
test.rb:3:in `foo': undefined local variable or method
`my_incorrectly_spelled_variable' for main:Object (NameError)
from test.rb:7:in `bar'
from test.rb:11:in `baz'
from test.rb:14:in `<main>'
def foo
my_correctly_spelled_variable = "hey!"
puts my_incorrectly_spelled_variable
end
def bar
my_incorrectly_spelled_variable = "hey!"
foo
end
def baz
my_incorrectly_spelled_variable = "hey!"
bar
end
baz
undefined local variable or method
`my_incorrectly_spelled_variable' for main:Object
(NameError)
➜ ombushop git:(master) ✗ ruby test.rb
test.rb:3:in `foo': undefined local variable or method
`my_incorrectly_spelled_variable' for main:Object (NameError)
from test.rb:8:in `bar'
from test.rb:13:in `baz'
from test.rb:16:in `<main>'
Gotchas and Stack Traces in Ruby
Gotchas and Stack Traces in Ruby
Gotchas and Stack Traces in Ruby
TL;DR: Always paste the full stack
trace of the error you come across
when asking for help.
THANK YOU!
questions?

More Related Content

PPTX
C++ Code as Seen by a Hypercritical Reviewer
Andrey Karpov
 
PPTX
What has to be paid attention when reviewing code of the library you develop
Andrey Karpov
 
PDF
Hidden Truths in Dead Software Paths
Ben Hermann
 
PDF
Type-Directed TDD in Rust: a case study using FizzBuzz
Franklin Chen
 
PDF
Analysis of the Trans-Proteomic Pipeline (TPP) project
PVS-Studio
 
PDF
Logical Expressions in C/C++. Mistakes Made by Professionals
PVS-Studio
 
DOCX
Memory in Cereal
Hanna Martin
 
DOCX
472_Strategies to Reduce Medication Errors
suneela amjad
 
C++ Code as Seen by a Hypercritical Reviewer
Andrey Karpov
 
What has to be paid attention when reviewing code of the library you develop
Andrey Karpov
 
Hidden Truths in Dead Software Paths
Ben Hermann
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Franklin Chen
 
Analysis of the Trans-Proteomic Pipeline (TPP) project
PVS-Studio
 
Logical Expressions in C/C++. Mistakes Made by Professionals
PVS-Studio
 
Memory in Cereal
Hanna Martin
 
472_Strategies to Reduce Medication Errors
suneela amjad
 

Viewers also liked (12)

DOC
Cine sunt eu in Cristos
William Anderson
 
PDF
8th alg -l9.5
jdurst65
 
PPT
Constelações maio
L Fernando F Pinto
 
PPT
Web Hechas a Mano
Luis Palomino
 
PDF
8th pre alg -l77
jdurst65
 
PDF
Artist brainstorm
katambwa
 
PPTX
Human Trafficking: Then and Now - The Story of the Armstrong Girl
Paul Milbank
 
PPT
Take Control of Email
jveldhoven
 
PPTX
BFRT
Zachary Lynch
 
PDF
Microeconomía 2016 ii. planificación de actividades académicas
Rafael Verde)
 
PDF
Body language tips for a successful presentation ABlyth2016
Andrew Blyth
 
PPTX
Proyecto desercion universitaria
Aniita Guajardo
 
Cine sunt eu in Cristos
William Anderson
 
8th alg -l9.5
jdurst65
 
Constelações maio
L Fernando F Pinto
 
Web Hechas a Mano
Luis Palomino
 
8th pre alg -l77
jdurst65
 
Artist brainstorm
katambwa
 
Human Trafficking: Then and Now - The Story of the Armstrong Girl
Paul Milbank
 
Take Control of Email
jveldhoven
 
Microeconomía 2016 ii. planificación de actividades académicas
Rafael Verde)
 
Body language tips for a successful presentation ABlyth2016
Andrew Blyth
 
Proyecto desercion universitaria
Aniita Guajardo
 
Ad

More from Ombu Labs, The Lean Software Boutique (19)

PDF
Trabajando en Código Abierto
Ombu Labs, The Lean Software Boutique
 
PDF
Design Patterns: Strategy and NullObject
Ombu Labs, The Lean Software Boutique
 
PDF
Our Values at The Lean Software Boutique
Ombu Labs, The Lean Software Boutique
 
PDF
A short guide to git's interactive rebase
Ombu Labs, The Lean Software Boutique
 
PDF
Open Source Recap (Dec '15) by etagwerker
Ombu Labs, The Lean Software Boutique
 
PPTX
Intro to Active Record
Ombu Labs, The Lean Software Boutique
 
PDF
Relational Databases 101
Ombu Labs, The Lean Software Boutique
 
PDF
The 7 Days Open Source Challenge
Ombu Labs, The Lean Software Boutique
 
PPTX
Basic memoization in Ruby
Ombu Labs, The Lean Software Boutique
 
PDF
Productivity Tips for Programmers
Ombu Labs, The Lean Software Boutique
 
PDF
Testing 101: Three Rules for Testing at Ombu Labs
Ombu Labs, The Lean Software Boutique
 
PDF
Peer Review Guidelines
Ombu Labs, The Lean Software Boutique
 
PDF
Recycling at Ombu Labs
Ombu Labs, The Lean Software Boutique
 
PDF
Guide to Services & Technology at Ombu Labs
Ombu Labs, The Lean Software Boutique
 
Trabajando en Código Abierto
Ombu Labs, The Lean Software Boutique
 
Design Patterns: Strategy and NullObject
Ombu Labs, The Lean Software Boutique
 
Our Values at The Lean Software Boutique
Ombu Labs, The Lean Software Boutique
 
A short guide to git's interactive rebase
Ombu Labs, The Lean Software Boutique
 
Open Source Recap (Dec '15) by etagwerker
Ombu Labs, The Lean Software Boutique
 
Relational Databases 101
Ombu Labs, The Lean Software Boutique
 
The 7 Days Open Source Challenge
Ombu Labs, The Lean Software Boutique
 
Basic memoization in Ruby
Ombu Labs, The Lean Software Boutique
 
Productivity Tips for Programmers
Ombu Labs, The Lean Software Boutique
 
Testing 101: Three Rules for Testing at Ombu Labs
Ombu Labs, The Lean Software Boutique
 
Guide to Services & Technology at Ombu Labs
Ombu Labs, The Lean Software Boutique
 
Ad

Recently uploaded (20)

PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 

Gotchas and Stack Traces in Ruby