SlideShare a Scribd company logo
1 of 16
Download to read offline
KON’NICHI WA, RUBY
               An introduction to Ruby with an appearance by Sinatra




Monday, September 27, 2010
Speaker.new({
                                :name => "Scotty Motte",
                                :twitter => "@spitfiresky",
                                :email => "scott@scottmotte.com"
                             })




Monday, September 27, 2010
ABOUT RUBY

    • Created                by Matz - he’s from Japan!

    • Written                for humans not for computers

    • Easy         to read and write
        •   5.times { puts “Arigato Matz! Have some chunky bacon!”}

        •   [‘riverside’, ‘japan’, ‘america’].each { |locale| puts
            locale.capitalize }


    •   Popularized by Ruby on Rails

Monday, September 27, 2010
INSTALLATION

    • Mac          Users, I say rejoice, for thou haveth Ruby already!

    • Windows   users - are you prejudiced towards Japan or
       something?! Let’s fix that by installing Ruby:

        • http://rubyinstaller.org/
                                  - follow the default installation steps
            and you are good to go. It will install to your programs
            directory.


Monday, September 27, 2010
IRB IS THE WORD
    •   irb - Interactive Ruby Console.
        The best way to tryout and learn
        Ruby.

    •   Comes packaged with your Ruby
        Install

    •   To Use:
        •   Mac: open up command line and
            type: irb
        •   Windows: open up Interactive
            Ruby program

Monday, September 27, 2010
IRB EXAMPLES
                     3.times { puts "da" }

                     ["paris", "france", "napoleon"].each { |name| puts
                     name.capitalize }

                     def say_hi_to(name)
                       puts "Please to meet you, #{name}!"
                     end
                     say_hi_to("Mr. President")

                     cost = 100
                     tax = 8.25
                     total = cost + tax
                     puts total




Monday, September 27, 2010
EVERYTHING IS AN OBJECT

                             1.class         # => Fixnum
                             'a'.class       # => String
                             :z.class        # => Symbol

                             class Foo
                               # something here
                             end
                             Foo.class       # => Class
                             Foo.new.class   # => Foo




Monday, September 27, 2010
DYNAMICALLY TYPED
       Basically, this means you don’t have to define things as
       integer or string before runtime.

                                def foo(bar)
                                  bar * 2
                                end

                                foo(1)     # => 2
                                foo("a")   # => "aa"



Monday, September 27, 2010
DUCK TYPING
       If it looks like a duck, walks, like a duck, and quacks like a
       duck, then it’s probably a duck.


                             "a".respond_to? :size   # => true
                             1.respond_to? :+        # => true
                             1.respond_to? :inject   # => false




Monday, September 27, 2010
MORE EXAMPLES OF RUBY
                       Strings
                       name = 'Riverside'
                       "Hello, #{name}!"

                       Methods
                       str = "Hello, Riverside"
                       str.size            # => 16
                       str.sub("Riverside", "World") # => "Hello, World!"

                       Numbers
                       1 + 9                # => 10

                       Arrays
                       [1, 2, 3]            # => [1, 2, 3]




Monday, September 27, 2010
MORE EXAMPLES OF RUBY
                             Hashes
                             options = {:name => "Riverside", :state => "CA"}

                             Iterators
                             [1,2,3].each {|n| puts n} # => 1 2 3

                             If/Elses
                             if something == 2
                               # do something
                             elsif something == 1
                               # do something
                             else
                               # do somthing else
                             end




Monday, September 27, 2010
ENTER SINATRA

    • Sinatra   is a web framework built on top of Ruby. It’s kinda like
       Rails, but much lighter. You use it to build websites with Ruby.

    • [sudo]            gem install sinatra

    • Gems    are just a cool word for ‘libraries’ in the Ruby world.
       They contain packaged up code that do cool things. Rails is a
       gem, Sinatra is a gem, and nokogiri is a gem. You can find gems
       at http://rubygems.org


Monday, September 27, 2010
PUT THIS IN YOUR PIPE




Monday, September 27, 2010
AND SMOKE IT




Monday, September 27, 2010
AND BLOW SMOKE RINGS




Monday, September 27, 2010
RESOURCES

    •   Ruby-Lang Homepage - http://www.ruby-lang.org/en/

    •   Windows Installer - http://rubyinstaller.org

    •   Ruby Gems - http://rubygems.org

    •   Sinatra - http://sinatrarb.com

    •   E-Text Editor (windows users) - http://www.e-texteditor.com/

    •   Textmate (mac users) - http://macromates.com/

    •   Why’s Poignant Guide to Ruby - http://mislav.uniqpath.com/poignant-guide/




Monday, September 27, 2010

More Related Content

Similar to Kon nichi wa_ruby

The Well-Grounded Nuby
The Well-Grounded NubyThe Well-Grounded Nuby
The Well-Grounded NubyDavid Black
 
Intro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady HackathonIntro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady Hackathonkdmcclin
 
Code@Six - Ruby 2.0
Code@Six - Ruby 2.0Code@Six - Ruby 2.0
Code@Six - Ruby 2.0shnikola
 
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 2Henry S
 
Making burgers with JavaScript
Making burgers with JavaScriptMaking burgers with JavaScript
Making burgers with JavaScriptDiogo Antunes
 
TechTalk #67 : Introduction to Ruby and Sinatra
TechTalk #67 : Introduction to Ruby and SinatraTechTalk #67 : Introduction to Ruby and Sinatra
TechTalk #67 : Introduction to Ruby and Sinatrabincangteknologi
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Let's talk about elixir - 26th Athens Ruby Meetup
Let's talk about elixir - 26th Athens Ruby MeetupLet's talk about elixir - 26th Athens Ruby Meetup
Let's talk about elixir - 26th Athens Ruby MeetupSkroutz S.A.
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Wen-Tien Chang
 
Rochester on Rails: Introduction to Ruby
Rochester on Rails: Introduction to RubyRochester on Rails: Introduction to Ruby
Rochester on Rails: Introduction to RubyJason Morrison
 

Similar to Kon nichi wa_ruby (20)

The Well-Grounded Nuby
The Well-Grounded NubyThe Well-Grounded Nuby
The Well-Grounded Nuby
 
Ruby 101
Ruby 101Ruby 101
Ruby 101
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Rejectkaigi 2010
Rejectkaigi 2010Rejectkaigi 2010
Rejectkaigi 2010
 
Mongo db
Mongo dbMongo db
Mongo db
 
Intro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady HackathonIntro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady Hackathon
 
Code@Six - Ruby 2.0
Code@Six - Ruby 2.0Code@Six - Ruby 2.0
Code@Six - Ruby 2.0
 
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
 
Making burgers with JavaScript
Making burgers with JavaScriptMaking burgers with JavaScript
Making burgers with JavaScript
 
Ruby and japanese
Ruby and japaneseRuby and japanese
Ruby and japanese
 
TechTalk #67 : Introduction to Ruby and Sinatra
TechTalk #67 : Introduction to Ruby and SinatraTechTalk #67 : Introduction to Ruby and Sinatra
TechTalk #67 : Introduction to Ruby and Sinatra
 
Perl Critic In Depth
Perl Critic In DepthPerl Critic In Depth
Perl Critic In Depth
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Let's talk about elixir - 26th Athens Ruby Meetup
Let's talk about elixir - 26th Athens Ruby MeetupLet's talk about elixir - 26th Athens Ruby Meetup
Let's talk about elixir - 26th Athens Ruby Meetup
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Rochester on Rails: Introduction to Ruby
Rochester on Rails: Introduction to RubyRochester on Rails: Introduction to Ruby
Rochester on Rails: Introduction to Ruby
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 
Ruby Programming
Ruby ProgrammingRuby Programming
Ruby Programming
 
Ruby.new @ VilniusRB
Ruby.new @ VilniusRBRuby.new @ VilniusRB
Ruby.new @ VilniusRB
 

Kon nichi wa_ruby

  • 1. KON’NICHI WA, RUBY An introduction to Ruby with an appearance by Sinatra Monday, September 27, 2010
  • 2. Speaker.new({ :name => "Scotty Motte", :twitter => "@spitfiresky", :email => "scott@scottmotte.com" }) Monday, September 27, 2010
  • 3. ABOUT RUBY • Created by Matz - he’s from Japan! • Written for humans not for computers • Easy to read and write • 5.times { puts “Arigato Matz! Have some chunky bacon!”} • [‘riverside’, ‘japan’, ‘america’].each { |locale| puts locale.capitalize } • Popularized by Ruby on Rails Monday, September 27, 2010
  • 4. INSTALLATION • Mac Users, I say rejoice, for thou haveth Ruby already! • Windows users - are you prejudiced towards Japan or something?! Let’s fix that by installing Ruby: • http://rubyinstaller.org/ - follow the default installation steps and you are good to go. It will install to your programs directory. Monday, September 27, 2010
  • 5. IRB IS THE WORD • irb - Interactive Ruby Console. The best way to tryout and learn Ruby. • Comes packaged with your Ruby Install • To Use: • Mac: open up command line and type: irb • Windows: open up Interactive Ruby program Monday, September 27, 2010
  • 6. IRB EXAMPLES 3.times { puts "da" } ["paris", "france", "napoleon"].each { |name| puts name.capitalize } def say_hi_to(name) puts "Please to meet you, #{name}!" end say_hi_to("Mr. President") cost = 100 tax = 8.25 total = cost + tax puts total Monday, September 27, 2010
  • 7. EVERYTHING IS AN OBJECT 1.class # => Fixnum 'a'.class # => String :z.class # => Symbol class Foo # something here end Foo.class # => Class Foo.new.class # => Foo Monday, September 27, 2010
  • 8. DYNAMICALLY TYPED Basically, this means you don’t have to define things as integer or string before runtime. def foo(bar) bar * 2 end foo(1) # => 2 foo("a") # => "aa" Monday, September 27, 2010
  • 9. DUCK TYPING If it looks like a duck, walks, like a duck, and quacks like a duck, then it’s probably a duck. "a".respond_to? :size # => true 1.respond_to? :+ # => true 1.respond_to? :inject # => false Monday, September 27, 2010
  • 10. MORE EXAMPLES OF RUBY Strings name = 'Riverside' "Hello, #{name}!" Methods str = "Hello, Riverside" str.size # => 16 str.sub("Riverside", "World") # => "Hello, World!" Numbers 1 + 9 # => 10 Arrays [1, 2, 3] # => [1, 2, 3] Monday, September 27, 2010
  • 11. MORE EXAMPLES OF RUBY Hashes options = {:name => "Riverside", :state => "CA"} Iterators [1,2,3].each {|n| puts n} # => 1 2 3 If/Elses if something == 2 # do something elsif something == 1 # do something else # do somthing else end Monday, September 27, 2010
  • 12. ENTER SINATRA • Sinatra is a web framework built on top of Ruby. It’s kinda like Rails, but much lighter. You use it to build websites with Ruby. • [sudo] gem install sinatra • Gems are just a cool word for ‘libraries’ in the Ruby world. They contain packaged up code that do cool things. Rails is a gem, Sinatra is a gem, and nokogiri is a gem. You can find gems at http://rubygems.org Monday, September 27, 2010
  • 13. PUT THIS IN YOUR PIPE Monday, September 27, 2010
  • 14. AND SMOKE IT Monday, September 27, 2010
  • 15. AND BLOW SMOKE RINGS Monday, September 27, 2010
  • 16. RESOURCES • Ruby-Lang Homepage - http://www.ruby-lang.org/en/ • Windows Installer - http://rubyinstaller.org • Ruby Gems - http://rubygems.org • Sinatra - http://sinatrarb.com • E-Text Editor (windows users) - http://www.e-texteditor.com/ • Textmate (mac users) - http://macromates.com/ • Why’s Poignant Guide to Ruby - http://mislav.uniqpath.com/poignant-guide/ Monday, September 27, 2010