SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Ruby Programming Language
puts “Hello Ruby!”
Clean, Elegant
      and
Meaningful Syntax
test_string = 'string for test'
puts 'matched' if test_string.match 'string'




files = Dir['*.txt']
for file in files
    file_ref = open file
    file_ref.each_line { |line| puts line.reverse.upcase }
end
Everything is an Object


10.times { puts “Hello World!” }   “Hello World!”.methods
Dynamic Typing,
  Duck Typing
     and
 Open Classes
a_variable = 'a b c'.split(' ')   #=> ['a','b','c']
a_variable = a_variable.join(' ') #=> 'a b c'



def a_function object_par
     puts object_par.crazy_method
end

a_function [1,2,3] #=> error: undefined method 'crazy_method' for class Array

class Array
    def crazy_method
         return 'crazy method for an array'
    end
end

a_function [1,2,3] #=> puts 'crazy method for an array'
a_variable = 'a b c'.split(' ')   #=> ['a','b','c']
a_variable = a_variable.join(' ') #=> 'a b c'



def a_function object_par
     puts object_par.crazy_method
end

a_function [1,2,3] #=> error: undefined method 'crazy_method' for class Array

class Array
    def crazy_method
         return 'crazy method for an array'
    end
end

a_function [1,2,3] #=> puts 'crazy method for an array'
def a_function object_par
     puts object_par.crazy_method
end

some_obj = SomeClass.new

a_function some_obj #=> error: undefined method 'crazy_method' for class SomeClass

def some_obj.crazy_method
     return 'this is a crazy feature'
end

a_function some_obj #=> puts 'this is a crazy_feature'
def a_function object_par
     puts object_par.crazy_method
end

some_obj = SomeClass.new

a_function some_obj #=> error: undefined method 'crazy_method' for class SomeClass

def some_obj.crazy_method
     return 'this is a crazy feature'
end

a_function some_obj #=> puts 'this is a crazy_feature'
"if it walks like a duck and quacks like a
           duck, then it is a duck”
Blocks
def square an_array
    return an_array.map { |e| e*e }
end




lines_of_a_doc.each_with_index do |line,i|
    if i.even? then
          puts 'even line: #{line}'
    else
          puts 'odd line: ' + line
    end
end
[1,2,3,4].select { |e| e.even? }
#=> [2,4]

[1,2,3,4].collect { |e| e.even? }
#=> [true,false,true,false]

[1,2,3,4].inject(0) { |sum,e| sum += e }
#=> 10
def my_for n
   n.times { |n| yield(n) }
end

my_for 3 { |i| puts i }

#=> 1
#=> 2
#=> 3
Mix-in
class Books < Collection
    def initialize
         @books = SomeReader.new('some_file_with_books').get_books
    end

      include Enumerable

      def each
          @books.each { |book| yield(book) }
      end
end




        Class Books now have
 map, select, inject, grep, find_all, include?
                 and more
Testing
require 'test/unit'

class TestHtmlParser < Test::Unit::TestCase

      must “find all imgs” do
          parser = HtmlParser.new '<div class='a'> <br/> <img src='img1.jpg'>n
                                   <p><img src='img2.jpg'></body>'
          assert_equal parser.parse_imgs, ['img1.jpg','img2.jpg']
      end
end

class HtmlParser

      def initialize html_doc
           @content = html_doc
      end

      def parse_imgs
          @content.scan(/imgs+src='(.+?)'/)
      end
end
Standard Library

● erb - .rhtml
● sockets

● threads

● html/xml parser

● ftp, http, imap, pop3, smtp

● tk

● pstore
And Gems!

$ gem install rails

$ gem install rspec

$ gem search twitter

 13,007 gems and counting!
Productivity and fun

    And that's it!



       Duda Dornelles
 dudassdornelles@gmail.com

Más contenido relacionado

Was ist angesagt?

Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby MetaprogrammingThaichor Seng
 
Rails 2010 Workshop
Rails 2010 WorkshopRails 2010 Workshop
Rails 2010 Workshopdtsadok
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in PythonBen James
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)brian d foy
 
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.Samuel Fortier-Galarneau
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Rolessartak
 
Moose: Perl Objects
Moose: Perl ObjectsMoose: Perl Objects
Moose: Perl ObjectsLambert Lum
 
Metaprogramming and Folly
Metaprogramming and FollyMetaprogramming and Folly
Metaprogramming and FollyHaseeb Qureshi
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Puppet
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet
 
Designing with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf IndiaDesigning with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf IndiaNaresha K
 
Python decorators
Python decoratorsPython decorators
Python decoratorsAlex Su
 
Constructive Destructor Use
Constructive Destructor UseConstructive Destructor Use
Constructive Destructor Usemetaperl
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteDr Nic Williams
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScriptStalin Thangaraj
 

Was ist angesagt? (19)

Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby Metaprogramming
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
Rails 2010 Workshop
Rails 2010 WorkshopRails 2010 Workshop
Rails 2010 Workshop
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in Python
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)
 
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
Decorators Explained: A Powerful Tool That Should Be in Your Python Toolbelt.
 
(Parameterized) Roles
(Parameterized) Roles(Parameterized) Roles
(Parameterized) Roles
 
Moose: Perl Objects
Moose: Perl ObjectsMoose: Perl Objects
Moose: Perl Objects
 
Metaprogramming and Folly
Metaprogramming and FollyMetaprogramming and Folly
Metaprogramming and Folly
 
Python decorators
Python decoratorsPython decorators
Python decorators
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
 
Designing with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf IndiaDesigning with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf India
 
Python decorators
Python decoratorsPython decorators
Python decorators
 
Constructive Destructor Use
Constructive Destructor UseConstructive Destructor Use
Constructive Destructor Use
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 

Andere mochten auch

İStanbulda GüNeş Konferansı
İStanbulda GüNeş KonferansıİStanbulda GüNeş Konferansı
İStanbulda GüNeş Konferansıhakki surel
 
How to Use HealthyCity.org for Grant Writing & Reporting
How to Use HealthyCity.org for Grant Writing & ReportingHow to Use HealthyCity.org for Grant Writing & Reporting
How to Use HealthyCity.org for Grant Writing & ReportingHealthy City
 
“Living A Spirit Filled Life"
“Living A Spirit Filled Life"“Living A Spirit Filled Life"
“Living A Spirit Filled Life"Don McClain
 
Corporate presentatie HRD adviesbureau GITP
Corporate presentatie HRD adviesbureau GITPCorporate presentatie HRD adviesbureau GITP
Corporate presentatie HRD adviesbureau GITPGITP
 
Whats Auth Got To Do With It
Whats Auth Got To Do With ItWhats Auth Got To Do With It
Whats Auth Got To Do With ItBryan Tuttle
 
University of Manchester PGT Administrator ETD Briefing Session
University of Manchester PGT Administrator ETD Briefing SessionUniversity of Manchester PGT Administrator ETD Briefing Session
University of Manchester PGT Administrator ETD Briefing SessionPhilip Butler
 
Henry Hobson Richardson
Henry Hobson RichardsonHenry Hobson Richardson
Henry Hobson Richardsongueste1c16e
 
我的照片
我的照片我的照片
我的照片wsb54321
 
When I Have A Convenient Season
When I Have A Convenient SeasonWhen I Have A Convenient Season
When I Have A Convenient SeasonDon McClain
 
Tinas Slide Show
Tinas Slide ShowTinas Slide Show
Tinas Slide Showmamafeenix
 
03 wrath of_god_against_jews
03 wrath of_god_against_jews03 wrath of_god_against_jews
03 wrath of_god_against_jewsDon McClain
 
Zealous for good
Zealous for goodZealous for good
Zealous for goodDon McClain
 
It Is Well With My Soul
It Is Well With My SoulIt Is Well With My Soul
It Is Well With My SoulDon McClain
 
мнения ученых о воде
мнения ученых о водемнения ученых о воде
мнения ученых о водеNeKsE
 
Henry Hobson Richardson
Henry Hobson RichardsonHenry Hobson Richardson
Henry Hobson Richardsongueste1c16e
 
Henry Hobson Richardson
Henry Hobson RichardsonHenry Hobson Richardson
Henry Hobson Richardsongueste1c16e
 

Andere mochten auch (20)

Wiki
WikiWiki
Wiki
 
3.30.2011
3.30.20113.30.2011
3.30.2011
 
İStanbulda GüNeş Konferansı
İStanbulda GüNeş KonferansıİStanbulda GüNeş Konferansı
İStanbulda GüNeş Konferansı
 
How to Use HealthyCity.org for Grant Writing & Reporting
How to Use HealthyCity.org for Grant Writing & ReportingHow to Use HealthyCity.org for Grant Writing & Reporting
How to Use HealthyCity.org for Grant Writing & Reporting
 
“Living A Spirit Filled Life"
“Living A Spirit Filled Life"“Living A Spirit Filled Life"
“Living A Spirit Filled Life"
 
Corporate presentatie HRD adviesbureau GITP
Corporate presentatie HRD adviesbureau GITPCorporate presentatie HRD adviesbureau GITP
Corporate presentatie HRD adviesbureau GITP
 
Whats Auth Got To Do With It
Whats Auth Got To Do With ItWhats Auth Got To Do With It
Whats Auth Got To Do With It
 
University of Manchester PGT Administrator ETD Briefing Session
University of Manchester PGT Administrator ETD Briefing SessionUniversity of Manchester PGT Administrator ETD Briefing Session
University of Manchester PGT Administrator ETD Briefing Session
 
Henry Hobson Richardson
Henry Hobson RichardsonHenry Hobson Richardson
Henry Hobson Richardson
 
我的照片
我的照片我的照片
我的照片
 
直角座標
直角座標直角座標
直角座標
 
When I Have A Convenient Season
When I Have A Convenient SeasonWhen I Have A Convenient Season
When I Have A Convenient Season
 
Tinas Slide Show
Tinas Slide ShowTinas Slide Show
Tinas Slide Show
 
03 wrath of_god_against_jews
03 wrath of_god_against_jews03 wrath of_god_against_jews
03 wrath of_god_against_jews
 
Zealous for good
Zealous for goodZealous for good
Zealous for good
 
FAREEDA moodboard
FAREEDA moodboardFAREEDA moodboard
FAREEDA moodboard
 
It Is Well With My Soul
It Is Well With My SoulIt Is Well With My Soul
It Is Well With My Soul
 
мнения ученых о воде
мнения ученых о водемнения ученых о воде
мнения ученых о воде
 
Henry Hobson Richardson
Henry Hobson RichardsonHenry Hobson Richardson
Henry Hobson Richardson
 
Henry Hobson Richardson
Henry Hobson RichardsonHenry Hobson Richardson
Henry Hobson Richardson
 

Ähnlich wie Ruby Programming Language

Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record.toster
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in RubyConFoo
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogrammingjoshbuddy
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyVysakh Sreenivasan
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a bossgsterndale
 

Ähnlich wie Ruby Programming Language (20)

Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
Ruby
RubyRuby
Ruby
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
Dsl
DslDsl
Dsl
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Language supports it
Language supports itLanguage supports it
Language supports it
 
Why ruby
Why rubyWhy ruby
Why ruby
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 

Ruby Programming Language

  • 3. Clean, Elegant and Meaningful Syntax
  • 4. test_string = 'string for test' puts 'matched' if test_string.match 'string' files = Dir['*.txt'] for file in files file_ref = open file file_ref.each_line { |line| puts line.reverse.upcase } end
  • 5. Everything is an Object 10.times { puts “Hello World!” } “Hello World!”.methods
  • 6. Dynamic Typing, Duck Typing and Open Classes
  • 7. a_variable = 'a b c'.split(' ') #=> ['a','b','c'] a_variable = a_variable.join(' ') #=> 'a b c' def a_function object_par puts object_par.crazy_method end a_function [1,2,3] #=> error: undefined method 'crazy_method' for class Array class Array def crazy_method return 'crazy method for an array' end end a_function [1,2,3] #=> puts 'crazy method for an array'
  • 8. a_variable = 'a b c'.split(' ') #=> ['a','b','c'] a_variable = a_variable.join(' ') #=> 'a b c' def a_function object_par puts object_par.crazy_method end a_function [1,2,3] #=> error: undefined method 'crazy_method' for class Array class Array def crazy_method return 'crazy method for an array' end end a_function [1,2,3] #=> puts 'crazy method for an array'
  • 9. def a_function object_par puts object_par.crazy_method end some_obj = SomeClass.new a_function some_obj #=> error: undefined method 'crazy_method' for class SomeClass def some_obj.crazy_method return 'this is a crazy feature' end a_function some_obj #=> puts 'this is a crazy_feature'
  • 10. def a_function object_par puts object_par.crazy_method end some_obj = SomeClass.new a_function some_obj #=> error: undefined method 'crazy_method' for class SomeClass def some_obj.crazy_method return 'this is a crazy feature' end a_function some_obj #=> puts 'this is a crazy_feature'
  • 11. "if it walks like a duck and quacks like a duck, then it is a duck”
  • 13. def square an_array return an_array.map { |e| e*e } end lines_of_a_doc.each_with_index do |line,i| if i.even? then puts 'even line: #{line}' else puts 'odd line: ' + line end end
  • 14. [1,2,3,4].select { |e| e.even? } #=> [2,4] [1,2,3,4].collect { |e| e.even? } #=> [true,false,true,false] [1,2,3,4].inject(0) { |sum,e| sum += e } #=> 10
  • 15. def my_for n n.times { |n| yield(n) } end my_for 3 { |i| puts i } #=> 1 #=> 2 #=> 3
  • 17. class Books < Collection def initialize @books = SomeReader.new('some_file_with_books').get_books end include Enumerable def each @books.each { |book| yield(book) } end end Class Books now have map, select, inject, grep, find_all, include? and more
  • 19. require 'test/unit' class TestHtmlParser < Test::Unit::TestCase must “find all imgs” do parser = HtmlParser.new '<div class='a'> <br/> <img src='img1.jpg'>n <p><img src='img2.jpg'></body>' assert_equal parser.parse_imgs, ['img1.jpg','img2.jpg'] end end class HtmlParser def initialize html_doc @content = html_doc end def parse_imgs @content.scan(/imgs+src='(.+?)'/) end end
  • 20. Standard Library ● erb - .rhtml ● sockets ● threads ● html/xml parser ● ftp, http, imap, pop3, smtp ● tk ● pstore
  • 21. And Gems! $ gem install rails $ gem install rspec $ gem search twitter 13,007 gems and counting!
  • 22. Productivity and fun And that's it! Duda Dornelles dudassdornelles@gmail.com