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

Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
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/ SpeakingJROOZ Review Center
 
Phrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntaxPhrase, clause, and sentence in syntax
Phrase, clause, and sentence in syntaxMuhamad Umar Chatab
 
English idioms
English idiomsEnglish idioms
English idiomssnowmaid
 
How to Teach Yourself to Code
How to Teach Yourself to CodeHow to Teach Yourself to Code
How to Teach Yourself to CodeMattan Griffel
 
Speaking English (Linking Words)
Speaking English  (Linking Words)Speaking English  (Linking Words)
Speaking English (Linking Words)sandeep J
 
Useful phrases for speaking
Useful phrases for speakingUseful phrases for speaking
Useful phrases for speakingandydei
 
Ppt on World Of Smartphones
Ppt on World Of SmartphonesPpt on World Of Smartphones
Ppt on World Of SmartphonesPulkit Syal
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java DevelopersRobert Reiz
 
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 skillsKinga Brady
 
Sense relations & Semantics
Sense relations & SemanticsSense relations & Semantics
Sense relations & SemanticsAfuza 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

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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.