SlideShare a Scribd company logo
1 of 88
Advanced Ruby Idioms So Clean
You Can Eat Off Of Them
Brian Guthrie
bguthrie@thoughtworks.com
http://twitter.com/bguthrie
What this talk is about
“magic”
http://www.flickr.com/photos/cayusa/2962437091/
encouraging you to try things
preventing you from poking
yourself with the sharp end of a
         pointed stick
magic
magic
technical understanding
design maturity
What this talk is not about
trying to stop you
explaining why
Who this talk is for
Who this talk is for




0-6 months   6-12 months    12-36 months   36+ months
Who this talk is for




0-6 months     6-12 months    12-36 months   36+ months
     total
  noob sauce
Who this talk is for




0-6 months     6-12 months    12-36 months         36+ months
     total                                     hardened
  noob sauce                                 ruby veteran
Who this talk is for




0-6 months     6-12 months              12-36 months         36+ months
     total       a danger to yourself                    hardened
  noob sauce         and others                        ruby veteran
Who this talk is for




0-6 months     6-12 months              12-36 months         36+ months
     total       a danger to yourself                    hardened
  noob sauce         and others                        ruby veteran




                You know who you are.
Who this talk is for




0-6 months     6-12 months                  12-36 months       36+ months
     total                                             thick controllers
                 total lack of curiousity
  noob sauce                                          (total noob sauce)
ask questions anytime
           http://www.flickr.com/photos/jonnya/4212907371/
task:
build a custom validation framework
task:
build a custom validation framework
            a danger to yourself
                and others
Tip

Offload the heavy stuff to dedicated objects.
                 It’s worth the trouble.
Tip

Make sure your subclasses honor the behavior
            of their superclasses.
                 It’s worth the trouble.
a brief detour
   http://www.flickr.com/photos/garyseven/4434835473/
6
  (acceptable)
    types of
      Ruby
method signatures
0
1
2
{}
1{}
*
0 1 2 H 1H *
0 1 2 ... n
H 1H *
Tip

Stick to the Six Acceptable Ruby Method Signatures.
                      0, 1, 2, H, 1H, *
a danger to yourself
    and others
Tip

       Add behavior with
instance_eval or define_method,
      not method_missing.
http://www.flickr.com/photos/suneko/389852016/
                                                +
                                                http://www.flickr.com/photos/contusion/4066189755/
validations anywhere!
>> Object.new.method :valid?
=> #<Method: Object#valid?>
>> Object.new.method :valid?
=> #<Method: Object(BrianRecord::Extensions::Validations::InstanceMethods)#valid?>
Tip

Modularize and name any extensions you build.
           Some poor sucker, like me, has to maintain that thing.
Tip

Use self.included to leverage existing class behaviors.
                      Purely my own opinion.
a_very_bad_gem/lib/extensions/object/tap.rb
Tip

         Extend respectfully:
Check for competing implementations.
          Or I will hunt you down and slay you.
Tip

Write tests.
Write tests.
Write tests.
Write tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
Write
tests.
YUM
RUBY WILL EAT YOU


 YUM
http://www.flickr.com/photos/pandiyan/146700348/
http://www.flickr.com/photos/bunchofpants/52816417/
Brian Guthrie
bguthrie@thoughtworks.com
http://twitter.com/bguthrie

questions?

More Related Content

Viewers also liked

Useful phrases for speaking
Useful phrases for speakingUseful phrases for speaking
Useful phrases for speaking
andydei
 
Sense relations & Semantics
Sense relations & SemanticsSense relations & Semantics
Sense relations & Semantics
Afuza Shara
 

Viewers also liked (14)

Idioms
IdiomsIdioms
Idioms
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
English Idioms
English IdiomsEnglish Idioms
English Idioms
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
IELTS Training - Misused Phrases in the IELTS Writing/ Speaking
IELTS Training - Misused Phrases in the IELTS Writing/ SpeakingIELTS Training - Misused Phrases in the IELTS Writing/ Speaking
IELTS Training - Misused Phrases in the IELTS Writing/ Speaking
 
Phrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntaxPhrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntax
 
English idioms
English idiomsEnglish idioms
English idioms
 
How to Teach Yourself to Code
How to Teach Yourself to CodeHow to Teach Yourself to Code
How to Teach Yourself to Code
 
Speaking English (Linking Words)
Speaking English  (Linking Words)Speaking English  (Linking Words)
Speaking English (Linking Words)
 
Useful phrases for speaking
Useful phrases for speakingUseful phrases for speaking
Useful phrases for speaking
 
Ppt on World Of Smartphones
Ppt on World Of SmartphonesPpt on World Of Smartphones
Ppt on World Of Smartphones
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
The Noun Phrase - Power up your description - Writing skills
The Noun Phrase - Power up your description - Writing skillsThe Noun Phrase - Power up your description - Writing skills
The Noun Phrase - Power up your description - Writing skills
 
Sense relations & Semantics
Sense relations & SemanticsSense relations & Semantics
Sense relations & Semantics
 

Recently uploaded

Recently uploaded (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Advanced Ruby Idioms So Clean You Can Eat Off Of Them

Editor's Notes

  1. tragically, a repeat offender as a framework writer I&amp;#x2019;m that guy; I just go write frameworks
  2. Look, you&apos;re going to go write a bunch of weird, crazy, and quite possibly criminally insane code in Ruby at some point or another in your career. Maybe you already have. I can&apos;t stop you, and I&apos;d be disappointed if you didn&apos;t at least try, so in this talk I&apos;ll show you how to do it without poking your own eye out with the pointy end of a sharpened stick.
  3. Explaining why you&amp;#x2019;d want to do these things Discouraging you from trying
  4. Look, you&apos;re going to go write a bunch of weird, crazy, and quite possibly criminally insane code in Ruby at some point or another in your career. Maybe you already have. I can&apos;t stop you, and I&apos;d be disappointed if you didn&apos;t at least try, so in this talk I&apos;ll show you how to do it without poking your own eye out with the pointy end of a sharpened stick.
  5. introduction; this is our goal; goals are important with DSLs
  6. simple lambda, no use of options
  7. slow, have to implement respond_to, have to call super, fairly complicated
  8. a little bit faster, still not exactly clear what&amp;#x2019;s going on
  9. faster yet, no memory leaks, a little bit clearer what&amp;#x2019;s going on--not EXACTLY rails convention
  10. a bad use of open classes, but even if good, there&amp;#x2019;s a problem
  11. Ruby is the name of the crocodile.
  12. Smart devs - obligation to team to condense &amp; beautify &amp; DRY out most commonly-used idioms Refactor and metaprogram more to domain, less to infrastructure
  13. Never again.