SlideShare une entreprise Scribd logo
1  sur  8
Ruby for Newbies




   Andrew Grimm
  University of New
    South Wales
What is Ruby?
Multi-paradigm language
  Object-oriented programming
  Functional programming
  Procedural programming
Just about everything is an Object
>> 42.is_a?(Object)
=> true
>> "hello world".is_a?(Object)
=> true
>> nil.is_a?(Object)
=> true
>> Object.is_a?(Object)
=> true
>> Class.is_a?(Object)
=> true
Just about all instructions are
               methods
puts “hello world” is a call to the method `puts`
>> private_methods.grep(/puts/)
=> ["puts"]
Enumerations
(1..5).each {|x| puts x}
(1..5).map {|x| x * 2}
(1..5).find_all {|x| x.odd?}
(1..5).sort_by {|x| [x.odd?.to_s, x]}
(1..5).group_by {|x| x.odd?}
Ruby (kind of) does functional
             programming
grouping_by = Proc.new {|x| x % 6 }
what_to_do = Proc.new {|x| p x}
numbers = 1..50

def group_by_and_process(numbers, grouping_by,
  what_to_do)
 what_to_do.call(numbers.group_by(&grouping_by))
end
Metaprogramming
plus = :+
number_1 = 12
number_2 = 30
number_1.send(plus, number_2) # => 42
You can do just about anything
old_stdout = STDOUT
STDOUT = StringIO.new
STDOUT.puts "this won't be printed"
STDOUT = old_stdout
STDOUT.puts "this will be printed"

Contenu connexe

Similaire à Ruby for newbies Lake Ainsworth

Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
Sergio Gil
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
chriseidhof
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
Paul Lam
 

Similaire à Ruby for newbies Lake Ainsworth (19)

The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Groovy
GroovyGroovy
Groovy
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Invoke Dynamic
Invoke DynamicInvoke Dynamic
Invoke Dynamic
 
Fp
FpFp
Fp
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovy
 
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code SmarterMachine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
 
Erlang/OTP for Rubyists
Erlang/OTP for RubyistsErlang/OTP for Rubyists
Erlang/OTP for Rubyists
 
Groovy unleashed
Groovy unleashed Groovy unleashed
Groovy unleashed
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Programming the cloud with Skywriting
Programming the cloud with SkywritingProgramming the cloud with Skywriting
Programming the cloud with Skywriting
 
Ruby Intro {spection}
Ruby Intro {spection}Ruby Intro {spection}
Ruby Intro {spection}
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 
Groovy!
Groovy!Groovy!
Groovy!
 
Clojure functions midje
Clojure functions midjeClojure functions midje
Clojure functions midje
 
Beauty and/or elegance in functional programming
Beauty and/or elegance in functional programmingBeauty and/or elegance in functional programming
Beauty and/or elegance in functional programming
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 

Plus de Andrew Grimm

All I want for Matz-mas
All I want for Matz-masAll I want for Matz-mas
All I want for Matz-mas
Andrew Grimm
 
Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011
Andrew Grimm
 
Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011
Andrew Grimm
 
Small eigen collider
Small eigen colliderSmall eigen collider
Small eigen collider
Andrew Grimm
 
Making easy roommate easy
Making easy roommate easyMaking easy roommate easy
Making easy roommate easy
Andrew Grimm
 
What has source control ever done for us?
What has source control ever done for us?What has source control ever done for us?
What has source control ever done for us?
Andrew Grimm
 

Plus de Andrew Grimm (20)

Finding Japanese flatmates with Ruby
Finding Japanese flatmates with RubyFinding Japanese flatmates with Ruby
Finding Japanese flatmates with Ruby
 
YHA Japan travel night (internet version)
YHA Japan travel night (internet version)YHA Japan travel night (internet version)
YHA Japan travel night (internet version)
 
Curing AIDS, with programming
Curing AIDS, with programmingCuring AIDS, with programming
Curing AIDS, with programming
 
Avoiding niseko syndrome
Avoiding niseko syndromeAvoiding niseko syndrome
Avoiding niseko syndrome
 
Curing AIDS, with programming
Curing AIDS, with programmingCuring AIDS, with programming
Curing AIDS, with programming
 
Memoirs of a programmer (internet version)
Memoirs of a programmer (internet version)Memoirs of a programmer (internet version)
Memoirs of a programmer (internet version)
 
Rubyist in oz
Rubyist in ozRubyist in oz
Rubyist in oz
 
Japanese: a programmers language
Japanese: a programmers languageJapanese: a programmers language
Japanese: a programmers language
 
Ruby 1.8.8 and professor
Ruby 1.8.8 and professorRuby 1.8.8 and professor
Ruby 1.8.8 and professor
 
Sapporo ruby kaigi
Sapporo ruby kaigiSapporo ruby kaigi
Sapporo ruby kaigi
 
How to talk like a ge1sha
How to talk like a ge1shaHow to talk like a ge1sha
How to talk like a ge1sha
 
All I want for Matz-mas
All I want for Matz-masAll I want for Matz-mas
All I want for Matz-mas
 
Ampersand method
Ampersand methodAmpersand method
Ampersand method
 
Nihon go do you speak it
Nihon go do you speak itNihon go do you speak it
Nihon go do you speak it
 
Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011
 
Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011Small eigen collider ruby kaigi 2011
Small eigen collider ruby kaigi 2011
 
Small eigen collider
Small eigen colliderSmall eigen collider
Small eigen collider
 
Making easy roommate easy
Making easy roommate easyMaking easy roommate easy
Making easy roommate easy
 
What has source control ever done for us?
What has source control ever done for us?What has source control ever done for us?
What has source control ever done for us?
 
Philosophy talk
Philosophy talkPhilosophy talk
Philosophy talk
 

Dernier

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 

Ruby for newbies Lake Ainsworth

  • 1. Ruby for Newbies Andrew Grimm University of New South Wales
  • 2. What is Ruby? Multi-paradigm language Object-oriented programming Functional programming Procedural programming
  • 3. Just about everything is an Object >> 42.is_a?(Object) => true >> "hello world".is_a?(Object) => true >> nil.is_a?(Object) => true >> Object.is_a?(Object) => true >> Class.is_a?(Object) => true
  • 4. Just about all instructions are methods puts “hello world” is a call to the method `puts` >> private_methods.grep(/puts/) => ["puts"]
  • 5. Enumerations (1..5).each {|x| puts x} (1..5).map {|x| x * 2} (1..5).find_all {|x| x.odd?} (1..5).sort_by {|x| [x.odd?.to_s, x]} (1..5).group_by {|x| x.odd?}
  • 6. Ruby (kind of) does functional programming grouping_by = Proc.new {|x| x % 6 } what_to_do = Proc.new {|x| p x} numbers = 1..50 def group_by_and_process(numbers, grouping_by, what_to_do) what_to_do.call(numbers.group_by(&grouping_by)) end
  • 7. Metaprogramming plus = :+ number_1 = 12 number_2 = 30 number_1.send(plus, number_2) # => 42
  • 8. You can do just about anything old_stdout = STDOUT STDOUT = StringIO.new STDOUT.puts "this won't be printed" STDOUT = old_stdout STDOUT.puts "this will be printed"