SlideShare a Scribd company logo
Ruby	
  
Facets	
  of	
  Ruby	
  
•  Object-­‐Oriented	
  to	
  the	
  core	
  
– Everything	
  is	
  an	
  object	
  
– Tight	
  encapsula<on	
  
– Single	
  Inheritance,	
  but	
  with	
  mixin	
  magic	
  
•  Dynamic	
  
– Duck	
  typing	
  
– Advanced	
  metaprogramming	
  
Elegant	
  
def	
  quicksort(a)	
  
	
  	
  return	
  a	
  if	
  a.length	
  <=	
  1	
  
	
  	
  pivot	
  =	
  a.shift	
  
	
  	
  split	
  =	
  a.partition	
  {|i|	
  i	
  <	
  pivot}	
  
	
  	
  (quicksort(split[0])	
  <<	
  pivot	
  <<	
  (quicksort(split[1]))).flatten	
  
end	
  
Concise	
  
def	
  fname_incr(fname)	
  
	
  	
  !File.exists?(fname)	
  ?	
  
	
  	
  	
  	
  fname	
  :	
  
	
  	
  	
  	
  	
  	
  /([0-­‐9]+)./.match(fname)	
  ?	
  
	
  	
  	
  	
  	
  	
  fname_incr(fname.sub(/([0-­‐9]+)/)	
  {	
  |m|	
  (m.to_i+1).to_s	
  })	
  :	
  
	
  	
  	
  	
  	
  	
  fname_incr(fname.sub(/[^.]*/)	
  {	
  |m|	
  m+'1'	
  })	
  
end	
  
Powerful	
  
def	
  traverse_tree(addition	
  =	
  '',	
  &proc)	
  
	
  yield	
  addition	
  +	
  "Q:	
  #{self.value}"	
  
	
  depth	
  =	
  $total_height	
  -­‐	
  self.height	
  
	
  #	
  add	
  1	
  to	
  depth	
  because	
  the	
  root	
  node	
  has	
  a	
  depth	
  of	
  0	
  
	
  self.yes.traverse_tree("n"+"t"*(depth+1),	
  &proc)	
  
	
  self.no.traverse_tree("n"+"t"*(depth+1),	
  &proc)	
  
end	
  

More Related Content

PDF
Lab: Foundation of Concurrent and Distributed Systems
KEY
Everything ruby
ODP
Ruby object model: A matter of life and death
ODP
PDF
Ruby everywhere
PDF
How to Become a Thought Leader in Your Niche
PDF
Ruby is an Acceptable Lisp
PPTX
Functional Programming in Javascript - IL Tech Talks week
Lab: Foundation of Concurrent and Distributed Systems
Everything ruby
Ruby object model: A matter of life and death
Ruby everywhere
How to Become a Thought Leader in Your Niche
Ruby is an Acceptable Lisp
Functional Programming in Javascript - IL Tech Talks week

Similar to What is Ruby? (10)

PDF
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
PDF
JRuby 9000 - Optimizing Above the JVM
PPTX
Elixir 5 minute intro
PDF
Clojure concurrency overview
PDF
Apache Flink & Graph Processing
KEY
Linuxconf 2011 parallel languages talk
PDF
Ruby Concurrency & Threads
PDF
Scaling Deep Learning with MXNet
PDF
Monadologie
PDF
Django Celery - A distributed task queue
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
JRuby 9000 - Optimizing Above the JVM
Elixir 5 minute intro
Clojure concurrency overview
Apache Flink & Graph Processing
Linuxconf 2011 parallel languages talk
Ruby Concurrency & Threads
Scaling Deep Learning with MXNet
Monadologie
Django Celery - A distributed task queue
Ad

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Introduction to Artificial Intelligence
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
history of c programming in notes for students .pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
AI in Product Development-omnex systems
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
medical staffing services at VALiNTRY
PPTX
Reimagine Home Health with the Power of Agentic AI​
Wondershare Filmora 15 Crack With Activation Key [2025
VVF-Customer-Presentation2025-Ver1.9.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
2025 Textile ERP Trends: SAP, Odoo & Oracle
How to Choose the Right IT Partner for Your Business in Malaysia
Introduction to Artificial Intelligence
How to Migrate SBCGlobal Email to Yahoo Easily
history of c programming in notes for students .pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
ai tools demonstartion for schools and inter college
AI in Product Development-omnex systems
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 41
System and Network Administration Chapter 2
Design an Analysis of Algorithms II-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Operating system designcfffgfgggggggvggggggggg
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
medical staffing services at VALiNTRY
Reimagine Home Health with the Power of Agentic AI​
Ad

What is Ruby?

  • 2. Facets  of  Ruby   •  Object-­‐Oriented  to  the  core   – Everything  is  an  object   – Tight  encapsula<on   – Single  Inheritance,  but  with  mixin  magic   •  Dynamic   – Duck  typing   – Advanced  metaprogramming  
  • 3. Elegant   def  quicksort(a)      return  a  if  a.length  <=  1      pivot  =  a.shift      split  =  a.partition  {|i|  i  <  pivot}      (quicksort(split[0])  <<  pivot  <<  (quicksort(split[1]))).flatten   end  
  • 4. Concise   def  fname_incr(fname)      !File.exists?(fname)  ?          fname  :              /([0-­‐9]+)./.match(fname)  ?              fname_incr(fname.sub(/([0-­‐9]+)/)  {  |m|  (m.to_i+1).to_s  })  :              fname_incr(fname.sub(/[^.]*/)  {  |m|  m+'1'  })   end  
  • 5. Powerful   def  traverse_tree(addition  =  '',  &proc)    yield  addition  +  "Q:  #{self.value}"    depth  =  $total_height  -­‐  self.height    #  add  1  to  depth  because  the  root  node  has  a  depth  of  0    self.yes.traverse_tree("n"+"t"*(depth+1),  &proc)    self.no.traverse_tree("n"+"t"*(depth+1),  &proc)   end