Ruby An Introduction

50 %
50 %
Information about Ruby An Introduction

Published on March 20, 2008

Author: tshrinivasan

Source: slideshare.net

Description

My Ruby Presentation on FossConf 2008,

FossConf'08 Ruby – An Introduction T.Shrinivasan tshrinivasan@gmail.com Indian Linux User Group, Chennai

Ruby is a Programming Language

There are so many  Programming Languages. Why  Ruby?

Ruby is simple and beautiful

Ruby is Easy to Learn

Ruby is Free Open Source Software

Ruby on Rails – Web Framework

RAA ● Ruby Application Archive ● 1648 projects ● http://raa.ruby-lang.org

Rubyforge ● 5070 projects and libraries ● http://rubyforge.org/

Can do ● Text Handling ● Games ● System Administration ● NLP ● GUI programming ● Web Applications ● ... ● Database Apps ● Scientific Applications

History

Ruby Yukihiro “Matz” Matsumoto Japan February 24, 1993

 Perl  Java  Python  Ruby  PHP 1987       1991         1993  1995

        What is Ruby?

Ruby is… A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

Quick and Easy ●      Intrepreted Scripting Language ●      Variable declarations are unnecessary ●      Variables are not typed ●      syntax is simple and consistent ●      memory management is automatic

Object Oriented Programming ●      Everything is an object ●      classes, methods, inheritance, etc. ●      singleton methods ●      quot;mixinquot; functionality by module ●      iterators and closures

Examples!

5.times { print “Ruby! quot; }

5.times { print “Ruby! quot; } Ruby! Ruby! Ruby! Ruby! Ruby!

Everything is an object

100.next

100.next 101

“I love Ruby”  .reverse.capitalize

“I love Ruby”  .reverse.capitalize “Ybur evol i”

3.hours.from_now

3.hours.from_now Thu Jan 19 22:05:00 Eastern  Standard Time 2006

Conventions

Variables colored_index_cards

Class Names Person

Symbols :street_name

Instance Variables @school_name

Constants Kilograms_Per_Pound

Input

puts “What is Your name?” name = gets name = name.chomp puts quot;Helloquot; + name + quot; .Welcomequot;

            Flow

if ( score >= 5000 ) puts “You win!” elsif ( score <= 0 ) puts “Game over.” else puts “Current score: #{score}” end

puts “PASS” if mark > 35

                    Loop

count = 0 5.times do count += 1 puts quot;Count =quot; + count.to_s end

Count = 1 Count = 2 Count = 3 Count = 4 Count = 5

count = 0 while count < 10 puts quot;Count = quot; +count.to_s count += 1 end

Blocks

1.upto(5) { |x| puts x } 1 2 3 4 5

5.downto(1) do |time| print “#{time}... ” puts “!” if time <= 3 end 5... 4... 3... ! 2... ! 1... !

Array

Array numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;, quot;threequot;, quot;fourquot; ]  

Array numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;, quot;threequot;, quot;fourquot; ]   >> numbers[0] => quot;zeroquot; >> numbers[4] => quot;fourquot;

Array numbers = [ quot;zeroquot;, quot;onequot;, quot;twoquot;, quot;threequot;, quot;fourquot; ] >> numbers[3].upcase => quot;THREEquot; >> numbers[3].reverse => quot;eerhtquot;

Sort Array primes = [ 11, 5, 7, 2, 13, 3 ]

Sort Array primes = [ 11, 5, 7, 2, 13, 3 ] primes.sort

Sort Array primes = [ 11, 5, 7, 2, 13, 3 ] primes.sort => [2, 3, 5, 7, 11, 13]

Sort Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;]

Sort Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;] names.sort

Sort Array names = [ quot;Shriniquot;, quot;Balaquot;, quot;Sureshquot;, quot;Arulquot;] names.sort =>[quot;Arulquot;, quot;Balaquot;, quot;Shriniquot;, quot;Sureshquot;]

More on Arrays ● Reverse ● Length ● Delete ● Join ● Find ● More than 100 methods

Hashes

menu = { :idly => 2.50, :dosai => 10.00, :coffee => 5.00, :ice_cream => 5.00 } menu[:idly] 2.50

Methods

Methods def say_hello(name) result = “Hello, #{name}!” return result end puts say_hello(“world”)

Methods def say_hello(name) “Hello, #{name}!” end puts say_hello(“world”)

Class

Classes class MathWhiz def say_square(value) puts value * value end end sam = MathWhiz.new sam.say_square(5)

Inheritance class Dog < Animal @catagory = “mammal” @legs = 4 end

Module

Modules module Trig PI = 3.141592654 def Trig.sin(x) # .. end def Trig.cos(x) # .. end end

Modules require quot;trigquot; y = Trig.sin(Trig::PI/4) 0.707106780551956

Attributes class PlainOldRubyObject attr_accessor :food, :drinks attr_reader :advice attr_writer :write_only end

Scope class Poet #public by default def poetry end protected def family_legacy end private def hopes_and_dreams end end

THE END of code :-)

How to Learn?

irb ● interactive ruby ● A ruby Shell ● Instance response ● learn as you type

Web sites Web Sites

http://ruby­lang.org www.ruby­lang.org

www.rubyforge.net

http://www.ruby­forum.com/

Training Centers

Ruby User Groups chennairb@googlegroups.com ● Mailing List ● Meetings ● Tutorial Sessions Join Today

We thank                         and                               for Photos Copyright (c)  2008    Permission is granted to copy, distribute and/or modify this document   under the terms of the GNU Free Documentation License, Version 1.2   or any later version published by the Free Software Foundation. http://www.gnu.org/copyleft/fdl.html   

#public presentations

Add a comment

Related presentations

Related pages

Introduction to Ruby

Introduction to Ruby. The Basics. First steps. First look at Ruby ; Ruby as a calculator; Numbers in Ruby . Integers; Floats ; More operators; Very large ...
Read more

Ruby introduction presentation - ruby-lang.org

Geschrieben von Matz am 13.7.2001. Ruby introduction presentation at New York City CTO club by Jim Menard on July 10, 2001.
Read more

Ruby on Rails: An Introduction - Johns Hopkins University ...

Ruby on Rails: An Introduction from Johns Hopkins University. Did you ever want to build a web application? Perhaps you even started down that path in a ...
Read more

Ruby in Twenty Minutes - Ruby Programming Language

Introduction. This is a small Ruby tutorial that should take no more than 20 minutes to complete. It makes the assumption that you already have Ruby installed.
Read more

Ruby Wizardry: An Introduction to Programming for Kids ...

Ruby Wizardry: An Introduction to Programming for Kids eBook: Eric Weinstein: Amazon.de: Kindle-Shop
Read more

An introduction to Ruby Programming: the history of Ruby.

An introduction to Ruby Programming - part of the free online book to learn the Ruby Programming language. Aimed at the inexperienced or completely new ...
Read more

Ruby Introduction: Ruby Tutorial - Learn Ruby

Ruby Tutorial: Introduction Using these Ruby Notes The Ruby Study Notes is a step-by-step tutorial to programming in Ruby and you can ...
Read more

Introduction to Ruby | Codecademy

Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular ...
Read more

Ruby Tutorial - Try Ruby

Learn the basic building blocks of the Ruby programming language in Code School’s Try Ruby course.
Read more

Ruby | Codecademy

Codecademy is the easiest way to learn how ... Companies like Twitter, Soundcloud, Goodreads, and Kickstarter got their products off the ground with Ruby ...
Read more