SlideShare a Scribd company logo
Intro to Ruby/Rails
Ruby vs. Rails
Ruby Rails
Ruby, Don't Take Your Love To Town
Ruby is "an interpreted scripting language for
quick and easy object-oriented programming“
Ruby‘s Arms
▪ interpreted
– powerful string operations and regular expressions
>> puts "Let's go" + " Nats!“
Let's go Nats!
– not compiled
▪ quick and easy
– variable declarations are unnecessary (random_statement = “this is a string”)
– it's all about happiness
▪ object oriented
– everything is an object ("hey does that mean that __ is an ob--" "yes“)
– classes, methods, inheritance
MINASWAN
▪ Yukihiro "Matz" Matsumoto
▪ “You want to enjoy life, don't
you? If you get your job done
quickly and your job is fun,
that's good isn't it?That's the
purpose of life, partly.Your life
is better.”
It’s really hard to avoid railroad puns
Rails is a “web application development framework written in
the Ruby language. It is designed to make programming web
applications easier by making assumptions about what every
developer needs to get started.”
Working on the Rails Road
▪ back end platform
– runs on a web server (server-side)
– interacts with front-end (in the browser, client-side) elements (HTML,CSS,
JavaScript)
▪ convention over configuration
– Rails expects you to follow certain conventions in exchange for sparing you time
spent on configuration
– easier to collaborate & increased productivity
▪ points of confusion
– when there's no convention
– changing the default
– Rails magic and obscurity
If Rails is the Creature
▪ David Heinemeier Hansson
(DHH)
▪ Drives racecars
▪ Created Rails for speed, self-
reliance, and programmer
happiness
▪ "If we don't have toys, we're
just adults."
Do I have to learn Ruby for Rails?
Yes
-- sort of
Let’s practice!
http://repl.it/
Common Ruby Data Types
▪ Numbers (Fixnum & Float)
– 120 & -1234 3.1415926 & 0.01
▪ Strings
– “I am a string.” “5” “true”
▪ Array
– [1, 2, 3, 4] [“apple”, “peach”, 8, “banana”, 1.0]
▪ Hash
– { “Jon Snow” => “Stark”, “Arya” => “Stark”, “Oberyn” => “Martell” }
– { “Dzhoy” => 86, “Paris” => 65, “Tiana” => 92, “Herve” => 45 }
Numbers
▪ Trying running the following code in the REPL (you can use your own
numbers, but make sure you use the same numbers each time)
print 4 / 2
print 4 % 2
print 4.0 / 2.0
print 4.0 % 2.0
▪ What output do you get? Can you venture a guess why?
Strings
▪ Lines of text composed of characters
>> puts "Let's go" + " Nats!“
Let's go Nats!
Variables
▪ Variables in math and programming are pretty similar
▪ Placeholders that represent or point to some value
– x = 5 name = “Tom Marvolo Riddle” numbers = [1, 2, 3, 4]
▪ Can be re-written/overwritten
name = “I am LordVoldemort”
Strings
▪ Lines of text composed of characters
>> puts "Let's go" + " Nats!“
Let's go Nats!
▪ Makes string interpolation easy by evaluating between the brackets
– x = 5 y = 10 “I ate #{x+y} grapes.” => “I ate 15 grapes.”
▪ Create a variable called name, assigned to a string of your name
▪ Create a variable assigned to the name of the person next to you
▪ Once you’ve done it in person, how would you introduce yourself to each
other in Ruby code using the variables?
▪ http://ruby-doc.org/core-2.2.0/String.html
Arrays
▪ Ordered collections of things: [“apple”, “peach”, 8, “banana”, 1.0]
▪ Items are accessed by the index number of the thing in square brackets : [#]
▪ Make an array of at least five things
– How do you access the fifth/last item?
– Given what you know about variables and accessing items, change the second element to
“banana”
– With this syntax, how might we add a new element to the array?
– Tough one: How would you delete “banana”?
▪ http://ruby-doc.org/core-2.2.0/Array.html
Hashes
▪ A collection of unique keys and their values
grades = { “Dzhoy” => 86, “Paris” => 65, “Tiana” => 92, “Herve” => 45 }
▪ Items are accessed with brackets just like arrays : [index]
▪ Make a hash of at least five things
– How do you access the fifth/last item?
– Given what you know about variables and accessing items, change the value of
the second key to “banana”
– With this syntax, how might we add a new element to the hash?
– Tough one: How would you delete “banana”?
▪ http://ruby-doc.org/core-2.2.0/Hash.html
Methods
▪ +, delete, print
def method_name(input)
what you want the method to do
end
▪ You call a method by its name and any input you’re providing
double_numbers ([1, 2, 5])
▪ Create a method that will take in a person’s name and return or print
out a greeting (ex: “Hello ______, nice to meet you!”)
– Hint: string interpolation (x = 5 y = 10 “I ate #{x+y} grapes.” => “I ate 15 grapes.”)
– Call your method a few times, passing it a different name each time
Iteration
▪ Hugely important bit of Ruby when making a Rails app
▪ Where the program loops through a set of things and performs an action
▪ syntax
variable.each do |x|
x.something (do this thing to each one)
end
names = ["joHN", "shaNNon", "Tyson", "lily"]
names.each do |name|
puts name.capitalize
end
Back to Rails
Is it the Only Game in Town?
Is it the Only Game in Town?
Who Uses Rails?
Is Rails Good for Everything?
Is Rails Good for Everything?
Resources
▪ Free
– Codecademy
– CodeSchool (partly)
– http://bit.ly/1T8IoL2 (Women Who Code DC Rails resource list)
– Railstutorial.org (free to read online)
– Jumpstart Labs Blogger
▪ Paid
– Udemy
– Udacity
– TeamTreeHouse (free trial option)
▪ Local Meetups
– Women Who Code DC (join our slack!)
– DCRUG (DC Ruby User’s Group)
– Arlington Ruby
– Ruby LoCo
Katherine McClintic
Software Engineer.Teacher. Musician. Fencer.
Person who likes to take things apart and usually
puts them back together in working order-er.
@scarletalphabet
Rails Lead forWomenWho Code DC meetup
http://installrails.com/

More Related Content

Similar to Intro to Ruby/Rails at TechLady Hackathon

Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
Erin Dees
 
Saigon Ruby Meetup 06/10/2015 - 5 Random Ruby Tips
Saigon Ruby Meetup 06/10/2015 - 5 Random Ruby TipsSaigon Ruby Meetup 06/10/2015 - 5 Random Ruby Tips
Saigon Ruby Meetup 06/10/2015 - 5 Random Ruby Tips
Futureworkz
 
Ruby 101
Ruby 101Ruby 101
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
Arulalan Ruby An Intro
Arulalan  Ruby An IntroArulalan  Ruby An Intro
Arulalan Ruby An Intro
Arulalan T
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
Robert Reiz
 
Rails Is From Mars Ruby Is From Venus Presentation 1
Rails Is From Mars  Ruby Is From Venus Presentation 1Rails Is From Mars  Ruby Is From Venus Presentation 1
Rails Is From Mars Ruby Is From Venus Presentation 1railsconf
 
Bhavesh ro r
Bhavesh ro rBhavesh ro r
Bhavesh ro r
bhavesh-gloscon
 
Dynamic languages, for software craftmanship group
Dynamic languages, for software craftmanship groupDynamic languages, for software craftmanship group
Dynamic languages, for software craftmanship group
Reuven Lerner
 
Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)
Karel Minarik
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
Wes Oldenbeuving
 
Test First Teaching
Test First TeachingTest First Teaching
Test First Teaching
Sarah Allen
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Wen-Tien Chang
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
James Thompson
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Aslak Hellesøy
 

Similar to Intro to Ruby/Rails at TechLady Hackathon (20)

Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
 
Saigon Ruby Meetup 06/10/2015 - 5 Random Ruby Tips
Saigon Ruby Meetup 06/10/2015 - 5 Random Ruby TipsSaigon Ruby Meetup 06/10/2015 - 5 Random Ruby Tips
Saigon Ruby Meetup 06/10/2015 - 5 Random Ruby Tips
 
Ruby 101
Ruby 101Ruby 101
Ruby 101
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Arulalan Ruby An Intro
Arulalan  Ruby An IntroArulalan  Ruby An Intro
Arulalan Ruby An Intro
 
[Start] Scala
[Start] Scala[Start] Scala
[Start] Scala
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
Rails Is From Mars Ruby Is From Venus Presentation 1
Rails Is From Mars  Ruby Is From Venus Presentation 1Rails Is From Mars  Ruby Is From Venus Presentation 1
Rails Is From Mars Ruby Is From Venus Presentation 1
 
Bhavesh ro r
Bhavesh ro rBhavesh ro r
Bhavesh ro r
 
Dynamic languages, for software craftmanship group
Dynamic languages, for software craftmanship groupDynamic languages, for software craftmanship group
Dynamic languages, for software craftmanship group
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Test First Teaching
Test First TeachingTest First Teaching
Test First Teaching
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Intro to Ruby/Rails at TechLady Hackathon

  • 3. Ruby, Don't Take Your Love To Town Ruby is "an interpreted scripting language for quick and easy object-oriented programming“
  • 4. Ruby‘s Arms ▪ interpreted – powerful string operations and regular expressions >> puts "Let's go" + " Nats!“ Let's go Nats! – not compiled ▪ quick and easy – variable declarations are unnecessary (random_statement = “this is a string”) – it's all about happiness ▪ object oriented – everything is an object ("hey does that mean that __ is an ob--" "yes“) – classes, methods, inheritance
  • 5. MINASWAN ▪ Yukihiro "Matz" Matsumoto ▪ “You want to enjoy life, don't you? If you get your job done quickly and your job is fun, that's good isn't it?That's the purpose of life, partly.Your life is better.”
  • 6. It’s really hard to avoid railroad puns Rails is a “web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started.”
  • 7. Working on the Rails Road ▪ back end platform – runs on a web server (server-side) – interacts with front-end (in the browser, client-side) elements (HTML,CSS, JavaScript) ▪ convention over configuration – Rails expects you to follow certain conventions in exchange for sparing you time spent on configuration – easier to collaborate & increased productivity ▪ points of confusion – when there's no convention – changing the default – Rails magic and obscurity
  • 8. If Rails is the Creature ▪ David Heinemeier Hansson (DHH) ▪ Drives racecars ▪ Created Rails for speed, self- reliance, and programmer happiness ▪ "If we don't have toys, we're just adults."
  • 9. Do I have to learn Ruby for Rails? Yes -- sort of
  • 11. Common Ruby Data Types ▪ Numbers (Fixnum & Float) – 120 & -1234 3.1415926 & 0.01 ▪ Strings – “I am a string.” “5” “true” ▪ Array – [1, 2, 3, 4] [“apple”, “peach”, 8, “banana”, 1.0] ▪ Hash – { “Jon Snow” => “Stark”, “Arya” => “Stark”, “Oberyn” => “Martell” } – { “Dzhoy” => 86, “Paris” => 65, “Tiana” => 92, “Herve” => 45 }
  • 12. Numbers ▪ Trying running the following code in the REPL (you can use your own numbers, but make sure you use the same numbers each time) print 4 / 2 print 4 % 2 print 4.0 / 2.0 print 4.0 % 2.0 ▪ What output do you get? Can you venture a guess why?
  • 13. Strings ▪ Lines of text composed of characters >> puts "Let's go" + " Nats!“ Let's go Nats!
  • 14. Variables ▪ Variables in math and programming are pretty similar ▪ Placeholders that represent or point to some value – x = 5 name = “Tom Marvolo Riddle” numbers = [1, 2, 3, 4] ▪ Can be re-written/overwritten name = “I am LordVoldemort”
  • 15. Strings ▪ Lines of text composed of characters >> puts "Let's go" + " Nats!“ Let's go Nats! ▪ Makes string interpolation easy by evaluating between the brackets – x = 5 y = 10 “I ate #{x+y} grapes.” => “I ate 15 grapes.” ▪ Create a variable called name, assigned to a string of your name ▪ Create a variable assigned to the name of the person next to you ▪ Once you’ve done it in person, how would you introduce yourself to each other in Ruby code using the variables? ▪ http://ruby-doc.org/core-2.2.0/String.html
  • 16. Arrays ▪ Ordered collections of things: [“apple”, “peach”, 8, “banana”, 1.0] ▪ Items are accessed by the index number of the thing in square brackets : [#] ▪ Make an array of at least five things – How do you access the fifth/last item? – Given what you know about variables and accessing items, change the second element to “banana” – With this syntax, how might we add a new element to the array? – Tough one: How would you delete “banana”? ▪ http://ruby-doc.org/core-2.2.0/Array.html
  • 17. Hashes ▪ A collection of unique keys and their values grades = { “Dzhoy” => 86, “Paris” => 65, “Tiana” => 92, “Herve” => 45 } ▪ Items are accessed with brackets just like arrays : [index] ▪ Make a hash of at least five things – How do you access the fifth/last item? – Given what you know about variables and accessing items, change the value of the second key to “banana” – With this syntax, how might we add a new element to the hash? – Tough one: How would you delete “banana”? ▪ http://ruby-doc.org/core-2.2.0/Hash.html
  • 18. Methods ▪ +, delete, print def method_name(input) what you want the method to do end ▪ You call a method by its name and any input you’re providing double_numbers ([1, 2, 5]) ▪ Create a method that will take in a person’s name and return or print out a greeting (ex: “Hello ______, nice to meet you!”) – Hint: string interpolation (x = 5 y = 10 “I ate #{x+y} grapes.” => “I ate 15 grapes.”) – Call your method a few times, passing it a different name each time
  • 19. Iteration ▪ Hugely important bit of Ruby when making a Rails app ▪ Where the program loops through a set of things and performs an action ▪ syntax variable.each do |x| x.something (do this thing to each one) end names = ["joHN", "shaNNon", "Tyson", "lily"] names.each do |name| puts name.capitalize end
  • 21. Is it the Only Game in Town?
  • 22. Is it the Only Game in Town?
  • 24.
  • 25.
  • 26.
  • 27. Is Rails Good for Everything?
  • 28. Is Rails Good for Everything?
  • 29. Resources ▪ Free – Codecademy – CodeSchool (partly) – http://bit.ly/1T8IoL2 (Women Who Code DC Rails resource list) – Railstutorial.org (free to read online) – Jumpstart Labs Blogger ▪ Paid – Udemy – Udacity – TeamTreeHouse (free trial option) ▪ Local Meetups – Women Who Code DC (join our slack!) – DCRUG (DC Ruby User’s Group) – Arlington Ruby – Ruby LoCo
  • 30. Katherine McClintic Software Engineer.Teacher. Musician. Fencer. Person who likes to take things apart and usually puts them back together in working order-er. @scarletalphabet Rails Lead forWomenWho Code DC meetup http://installrails.com/

Editor's Notes

  1. Before I start, I have a question. How many of you here would say that you’ve never programmed before? How many of you with hands raised have ever used Excel? You have programmed before. Excel (and similar) is at it’s heart, programming, just on a basic but important data entry level. Welcome to a brief intro session on Ruby and Rails. I’m going to spend a little bit of time talking about the two generally, then we’ll get our hands on some actual code without having to install anything, and then I’ll leave time at the end for questions and installation issues. I’ll tweet out a link to the presentation after and post in Slack so don’t feel like you have to write anything down if you don’t want to. (3:30-4:20)
  2. You may have several variations of Ruby, Rails, Ruby/Rails, Ruby on Rails, or something else floating around, but what does that mean. If what I’m talking to you about is Ruby on Rails, what’s the difference? I like to think of Ruby as the raw ingredients. The flour, the sugar, the fat, and so on. You can make a great cake from scratch. But that takes a lot of time and you risk the possibility of not getting the mix exactly right. That’s where Rails comes in. Rails is a framework for Ruby, so in this analogy it’s sort of the boxed cake mix. It’s still got flour and sugar and so on inside it, but it’s packaged up to be quick easy to use. You can customize it for your own needs, but you don’t have to in order to get a great cake out of it.
  3. I say this mainly for the benefit of those of you with programming experience in other languages, but Ruby describes as an interpreted scripting language for quick and easy object-oriented programming. This may be your face right now and that’s okay. We’ll dive into it a bit.
  4. So first off, interpreted. For those of you who are coming from other languages like C or Java, Ruby is different because you don’t have to compile it first. The moment you type in a command, it reads it, parses it, and executes it. Assuming it’s a complete command anyhow. Now quick and easy. Unlike other languages where you have to tell it that an integer is an integer, or a string (bit of text) is a string, Ruby understands that automatically. Now object oriented. Ruby, like other object oriented languages, essentially functions by sending messages between objects. Even in a simple arithmetic problem like 1 + 2 you’re sending the addition message between 1 and 2 and because they’re both numbers (integers) they know what the plus sign means. Object oriented languages also make it easier to organize similar code to avoid repetition.
  5. Matz is Nice and so We are Nice Remember when I mentioned that Ruby is all about happiness? Well this is its creator, Matz. Every time he was faced with a decision when making Ruby where he could make it run a little faster or he could make the programmer happier, he chose happier every time.
  6. So on to Rails. Again, this may be your face right now and that’s okay. We’ll dive into this too a bit.
  7. Backend Convention over configuration When there’s no convention, people often turn to gems, prepackaged bits of code that you can add to your app. Other languages and frameworks might call them libraries or packages, or modules or something else entirely.
  8. So if Rails is the creation, if it’s the creature, who is Dr. Frankenstein? Well, it’s this guy. DHH as he’s known. He looks less like a member of a European boyband now, but this is still the picture of him that most places use, including his own website. Obligatory information: he drives racecars. The reason why Rails is so popular with startups is that it was created to enable small teams or individuals to build with speed, and to enjoy it. A lot like Matz’s goal with Ruby.
  9. So you might be wondering if you have to learn Ruby to do Rails. The answer is:
  10. Most of you probably want to focus on Rails, so let’s work with some elements of Ruby that will improve the ease of working with Rails. If you have a Mac I believe you should have Ruby installed already so you can open up a terminal or iTerm window, but otherwise please go to the address on the screen and click on Ruby. This is an online interpreter that will Read, Evaluate (or run) and Print your code. That’s why it’s called a REPL (a read, evaluate, print loop). There are other ones you can use for apps, but this will enable us to work some basic Ruby code without installing anything.
  11. FixNum == Integer
  12. Out of curiosity, did anyone try running it without the print statement? The print statement is just to be able to run all four lines at once but separately so it doesn’t think it’s all part of the same code block and just return the last statement it evaluates. Aside from adding and subtracting and such, how do you think that understanding Ruby numbers will help in a Rails web application? (e-commerce)
  13. Basically if it’s in quotes, it’s a string. Doesn’t matter if a number’s within those quotes or not. Just as a way of storing text you can see already why Ruby’s strings are important in a Rails app, but to really see the power of strings we’re going to need to take a quick detour.
  14. Who remembers or knows what variables are used for in math? Well they’re a great way for temporarily saving or storing a reference to something that you’re going to want to use again. Do I want to print out that name all over my page? Do I want to do some operations on that collection of numbers? Putting in the variable makes it easy.
  15. Back to strings. How many of you have ever played a video or computer game where you start by creating a character and giving it a name, and then as you play other characters greet you by saying something like Hello, your character’s name? Ever wondered how they do that, aside from perhaps assuming the logic behind it? Run it (or press return if you’re using your terminal) just to make sure that it works.
  16. Make an array of at least five things, making sure you’re setting it equal to a variable so we can access it later. Maybe your favorite foods or favorite numbers or favorite tv shows. Keep in mind what we’ve learned about how to write strings. This was a bit of a trick question. In Ruby, like many other languages, the first item is the 0th item. Sort of like a newborn exists but is 0 years old. There are other, sometimes better ways of doing this, but for consistency we’ll keep with this syntax for now. This touches on something we’ll get to creating in a bit, called methods. Methods, whether built into Ruby or what you create, are the messages you’re sending telling things what action to take. In this case, delete deletes a particular element everywhere it occurs in an array, and delete_at deletes at a particular index. How might arrays be useful in a Rails app, say in a blog? What are some things you might want to do to an array of stuff in a Rails app?
  17. Keys are unique, so you can’t use them more than once. So for this example I couldn’t have Paris get a grade of 65 and another grade of 87 say. Hash items are accessed just like arrays, but unlike arrays, any object can be a key. Maybe tv shows or movies and their ratings, or how you liked them on a scale of 1-10. Maybe items like food or animals or people and a brief description. This one’s a little harder to see outright, but how might hashes be useful in a Rails app? What are some things you might want to do to a hash of stuff in a Rails app? (think username => “username” password => “password” database check)
  18. You’ve seen some built-in Ruby methods already, like +, %, /, delete, and print. Now let’s put together some things we’ve learned already and create our own. A Ruby method starts with the abbreviation “def”, as in define. Method names in Ruby are lower-case and what’s called snake case (or connected by an underscore) if they’re more than one word. If you want your method to take any arguments, or input, you put that in parentheses after the name. The indented block of code describes what you want the method to do, and you close it all off by the word “end”. You call a method by: You can also call a method directly on something. *GO TO REPL* Say you have this shout. Doesn’t look really threatning does it. Try calling upcase on it. How about now?
  19. Sometimes the looping can be conditional, like “do this while this condition is true”, and sometimes it’s what you do for the whole set. The syntax looks like this. You call each on whatever variable refers to the collection, and tell it to do something for each element. The x between the pipe characters here is a kind of temporary placeholder that stands for the thing that you want to manipulate. You can name it anything, and should name it something that makes sense with the data you’re using. Why do you think I said this is super important to Rails?
  20. You’ve seen some elements of Ruby that are involved somehow in Rails, so let’s get back to Rails.
  21. While we haven’t done anything specifically with Rails, with the tech community’s focus on Rails, is Rails the only Ruby framework? The only boxed cake mix around?
  22. No, but, and let’s ignore the second one for a moment, it might as well be. It’s so popular compared to the next most popular one that few major companies use anything else. When trying to think of a well known company or organization that does Ruby on another framework, the only one I could come up with is the NSA, for reasons I can theorize later if you’re curious.
  23. Rails is popular with startups like these because it allows a small team or individual to create at least a basic version of an app fairly quickly. So why doesn’t everybody use it?
  24. You may have heard that Twitter was built with Rails. So where Rails falters is in scaling up to handle giant apps where hundreds of thousands of users transmit and save data at any single second.
  25. So Twitter had to move off of Rails. But as you’ve just seen, Rails does a pretty good job for other companies that are household names.
  26. Before we get to the installation part, I want to finish this off with a list of resources you might want to look into for future learning. I’ll tweet out a link to the presentation after so you don’t have to copy this all down.