SlideShare a Scribd company logo
Ruby Projects  and  Libraries Vorleak Chy (vorleak.chy@gmail.com) Software Engineer Yoolk Inc http://groups.google.com/group/khmertech/
Agenda Projects and Using Code from Other Files Libraries RubyGems
Introduction Using code already written and prepared by other developers within your own applications
Projects and Using Code from Other Files Basic File Inclusion Inclusions from Other Directories Logic and Including Code Nested Inclusions
Basic File Inclusion Uses the require or load command to load the external file into the current program #file: string_extensions.rb class String def vowels self.scan(/[aeiou]/i) end end #file: vowel_test.rb require 'string_extensions' puts "This is a test".vowels.join('-')
Basic File Inclusion (Cont.) Ruby programmers generally use require rather than load. The effects of load are only useful if the code in the external file has changed or if it contains active code that will be  executed immediately #file: b.rb load 'a' puts "Hello from b.rb" load 'a' puts "Hello again from b.rb" #result output Hello from a.rb Hello from b.rb Hello from a.rb Hello again from b.rb #file: a.rb puts "Hello from a.rb"
Inclusions from Other Directories The process of require and load First looks the file in the current folder Second looks the file in the various folders where Ruby stores its own file and libraries Lists of directories to search for included files in a special variable called $:. $:.each { |d| puts d } /usr/local/lib/ruby/site_ruby/1.8 /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.1 /usr/local/lib/ruby/site_ruby ...
Inclusions from Other Directories (Cont.) Adds extra folders to search the file $: is an array, so you can push extra items to it $:.push '/your/directory/here' require 'yourfile'
Logic and Including Code Adds logic to the require or load command $debug_mode = 0 require $debug_mode == 0 ? "normal-classes" : "debug-classes" %w{file1 file2 file3 file4 file5}.each { |l| require l }
Nested Inclusions Code from files that are included into others with require and load has the same freedom as if the code were pasted directly into the original file. #file: a.rb require 'b' #And b.rb contains the following: require 'c' #And c.rb contains the following: def example puts "Hello!" end #And d.rb contains the following: require 'a' example
Libraries Collection of routines that can be called by separate programs, but that exist independently of those programs. A list of all the standard libraries, including documentation, is available at http://www.ruby-doc.org/stdlib/ How to use two standard libraries
net/http Library HTTP stands for HyperText Transfer Protocol, and it’s the main protocol that makes the World Wide Web work, as it provides the mechanism by which Web pages, files, and other media can be sent between Web servers and clients require 'net/http' Net::HTTP.get_print('www.rubyinside.com', '/') require 'net/http' url = URI.parse('http://www.rubyinside.com/') response = Net::HTTP.start(url.host, url.port) do |http| http.get(url.path) end content = response.body
OpenStruct Library More flexible than Struct Creates data objects without specifying the attributes Create attributes on the fly #struct Person = Struct.new(:name, :age) me = Person.new("Fred Bloggs", 25) me.age += 1 #openStruct require 'ostruct' person = OpenStruct.new person.name = "Fred Bloggs" person.age = 25
RubyGems Packaging system for Ruby programs and libraries. Manages different versions of the same libraries on your PC
Installing RubyGems Before you can use RubyGems, it’s necessary to install it On Windows, if you installed Ruby using the “one-click installer”, you already have RubyGem installed On Mac OS X, Linux, and Other Unix  After you installed you can type gem
Finding Gems Lists of the gems that are installed  gem list Queries the remote gem server gem list --remote gem query --remote --name-matches class Queries the remote gem server and match the name “class”
Installing a Simple Gem Installs “feedtools” gem install feedtools #if it can't install probably sudo gem install feedtools
Using Gems RubyGems system isn’t an integrated part of Ruby It’s necessary to tell your programs that you want to use and load gems require 'rubygems' require 'RedCloth' r = RedCloth.new("this is a *test* of _using RedCloth_") puts r.to_html
Installing a More Complex Gem You may want to install “hpricot” in specific source for latest version gem install hpricot --source code.whytheluckystiff.net
Upgrading and Uninstalling Gems Update all of your currently installed gems gem update Uninstall gems “feedtools”  gem uninstall feedtools $ gem uninstall rubyforge Uninstall all gem versions “rubyforge”
 
Thank-you for attending Feel free to join at http ://groups.google.com/group/khmertech/ KhmerTech

More Related Content

What's hot (20)

PDF
Mastering Maven 2.0 In 1 Hour V1.3
Matthew McCullough
 
PDF
Composer for Busy Developers - php|tek13
Rafael Dohms
 
PDF
Construire son JDK en 10 étapes
José Paumard
 
PDF
A python web service
Temian Vlad
 
PDF
Dependency management with Composer
Jason Grimes
 
PDF
A History of PHP
Xinchen Hui
 
KEY
LvivPy - Flask in details
Max Klymyshyn
 
PPTX
PHP Dependency Management with Composer
Adam Englander
 
PDF
Composer the right way - SunshinePHP
Rafael Dohms
 
PDF
Web develop in flask
Jim Yeh
 
PPT
An Introduction to Solr
tomhill
 
PDF
Rest API using Flask & SqlAlchemy
Alessandro Cucci
 
ODP
Website releases made easy with the PEAR installer, OSCON 2009
Helgi Þormar Þorbjörnsson
 
ODP
The Gory Details of Debian packages
Jeremiah Foster
 
PDF
PM : code faster
PHPPRO
 
PDF
Flask Basics
Eueung Mulyana
 
PDF
Flask With Server-Sent Event
Tencent
 
PPT
Securing Your Web Server
manugoel2003
 
PPTX
PHP Presentation
JIGAR MAKHIJA
 
Mastering Maven 2.0 In 1 Hour V1.3
Matthew McCullough
 
Composer for Busy Developers - php|tek13
Rafael Dohms
 
Construire son JDK en 10 étapes
José Paumard
 
A python web service
Temian Vlad
 
Dependency management with Composer
Jason Grimes
 
A History of PHP
Xinchen Hui
 
LvivPy - Flask in details
Max Klymyshyn
 
PHP Dependency Management with Composer
Adam Englander
 
Composer the right way - SunshinePHP
Rafael Dohms
 
Web develop in flask
Jim Yeh
 
An Introduction to Solr
tomhill
 
Rest API using Flask & SqlAlchemy
Alessandro Cucci
 
Website releases made easy with the PEAR installer, OSCON 2009
Helgi Þormar Þorbjörnsson
 
The Gory Details of Debian packages
Jeremiah Foster
 
PM : code faster
PHPPRO
 
Flask Basics
Eueung Mulyana
 
Flask With Server-Sent Event
Tencent
 
Securing Your Web Server
manugoel2003
 
PHP Presentation
JIGAR MAKHIJA
 

Viewers also liked (6)

PPT
Refactoring, A First Example
Vorleak Chy
 
PPTX
Introduction to Refactoring
Vorleak Chy
 
PPT
Rasberry Green Tea
jzinda
 
PDF
Seminar Presentation on Raspberry Pi
Shahrikh Khan
 
PDF
Hype vs. Reality: The AI Explainer
Luminary Labs
 
PDF
Study: The Future of VR, AR and Self-Driving Cars
LinkedIn
 
Refactoring, A First Example
Vorleak Chy
 
Introduction to Refactoring
Vorleak Chy
 
Rasberry Green Tea
jzinda
 
Seminar Presentation on Raspberry Pi
Shahrikh Khan
 
Hype vs. Reality: The AI Explainer
Luminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
LinkedIn
 
Ad

Similar to Ruby Projects and Libraries (20)

KEY
Introducing Ruby
James Thompson
 
PDF
IJTC%202009%20JRuby
tutorialsruby
 
PDF
IJTC%202009%20JRuby
tutorialsruby
 
PDF
Ruby Presentation - Article
Christopher Giroir
 
KEY
Ruby v cpp_preso
jessicard
 
PDF
Ruby Presentation
platico_dev
 
PDF
Introduction to Ruby
MobME Technical
 
PDF
Writing a Ruby Gem for beginners
ConFoo
 
PPTX
Ruby for PHP developers
Max Titov
 
KEY
Introduction to Ruby
Mark Menard
 
PDF
Ruby training day1
Bindesh Vijayan
 
PPT
Workin ontherailsroad
Jim Jones
 
PPT
WorkinOnTheRailsRoad
webuploader
 
DOCX
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid
 
KEY
Week5
reneedv
 
KEY
Ruby on Rails Training - Module 1
Mark Menard
 
KEY
Week6
reneedv
 
KEY
Module Magic
James Gray
 
ODP
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
rivierarb
 
Introducing Ruby
James Thompson
 
IJTC%202009%20JRuby
tutorialsruby
 
IJTC%202009%20JRuby
tutorialsruby
 
Ruby Presentation - Article
Christopher Giroir
 
Ruby v cpp_preso
jessicard
 
Ruby Presentation
platico_dev
 
Introduction to Ruby
MobME Technical
 
Writing a Ruby Gem for beginners
ConFoo
 
Ruby for PHP developers
Max Titov
 
Introduction to Ruby
Mark Menard
 
Ruby training day1
Bindesh Vijayan
 
Workin ontherailsroad
Jim Jones
 
WorkinOnTheRailsRoad
webuploader
 
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid
 
Week5
reneedv
 
Ruby on Rails Training - Module 1
Mark Menard
 
Week6
reneedv
 
Module Magic
James Gray
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
rivierarb
 
Ad

Recently uploaded (20)

PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
community health nursing question paper 2.pdf
Prince kumar
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 

Ruby Projects and Libraries

  • 1. Ruby Projects and Libraries Vorleak Chy ([email protected]) Software Engineer Yoolk Inc http://groups.google.com/group/khmertech/
  • 2. Agenda Projects and Using Code from Other Files Libraries RubyGems
  • 3. Introduction Using code already written and prepared by other developers within your own applications
  • 4. Projects and Using Code from Other Files Basic File Inclusion Inclusions from Other Directories Logic and Including Code Nested Inclusions
  • 5. Basic File Inclusion Uses the require or load command to load the external file into the current program #file: string_extensions.rb class String def vowels self.scan(/[aeiou]/i) end end #file: vowel_test.rb require 'string_extensions' puts "This is a test".vowels.join('-')
  • 6. Basic File Inclusion (Cont.) Ruby programmers generally use require rather than load. The effects of load are only useful if the code in the external file has changed or if it contains active code that will be executed immediately #file: b.rb load 'a' puts "Hello from b.rb" load 'a' puts "Hello again from b.rb" #result output Hello from a.rb Hello from b.rb Hello from a.rb Hello again from b.rb #file: a.rb puts "Hello from a.rb"
  • 7. Inclusions from Other Directories The process of require and load First looks the file in the current folder Second looks the file in the various folders where Ruby stores its own file and libraries Lists of directories to search for included files in a special variable called $:. $:.each { |d| puts d } /usr/local/lib/ruby/site_ruby/1.8 /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.1 /usr/local/lib/ruby/site_ruby ...
  • 8. Inclusions from Other Directories (Cont.) Adds extra folders to search the file $: is an array, so you can push extra items to it $:.push '/your/directory/here' require 'yourfile'
  • 9. Logic and Including Code Adds logic to the require or load command $debug_mode = 0 require $debug_mode == 0 ? "normal-classes" : "debug-classes" %w{file1 file2 file3 file4 file5}.each { |l| require l }
  • 10. Nested Inclusions Code from files that are included into others with require and load has the same freedom as if the code were pasted directly into the original file. #file: a.rb require 'b' #And b.rb contains the following: require 'c' #And c.rb contains the following: def example puts "Hello!" end #And d.rb contains the following: require 'a' example
  • 11. Libraries Collection of routines that can be called by separate programs, but that exist independently of those programs. A list of all the standard libraries, including documentation, is available at http://www.ruby-doc.org/stdlib/ How to use two standard libraries
  • 12. net/http Library HTTP stands for HyperText Transfer Protocol, and it’s the main protocol that makes the World Wide Web work, as it provides the mechanism by which Web pages, files, and other media can be sent between Web servers and clients require 'net/http' Net::HTTP.get_print('www.rubyinside.com', '/') require 'net/http' url = URI.parse('http://www.rubyinside.com/') response = Net::HTTP.start(url.host, url.port) do |http| http.get(url.path) end content = response.body
  • 13. OpenStruct Library More flexible than Struct Creates data objects without specifying the attributes Create attributes on the fly #struct Person = Struct.new(:name, :age) me = Person.new("Fred Bloggs", 25) me.age += 1 #openStruct require 'ostruct' person = OpenStruct.new person.name = "Fred Bloggs" person.age = 25
  • 14. RubyGems Packaging system for Ruby programs and libraries. Manages different versions of the same libraries on your PC
  • 15. Installing RubyGems Before you can use RubyGems, it’s necessary to install it On Windows, if you installed Ruby using the “one-click installer”, you already have RubyGem installed On Mac OS X, Linux, and Other Unix After you installed you can type gem
  • 16. Finding Gems Lists of the gems that are installed gem list Queries the remote gem server gem list --remote gem query --remote --name-matches class Queries the remote gem server and match the name “class”
  • 17. Installing a Simple Gem Installs “feedtools” gem install feedtools #if it can't install probably sudo gem install feedtools
  • 18. Using Gems RubyGems system isn’t an integrated part of Ruby It’s necessary to tell your programs that you want to use and load gems require 'rubygems' require 'RedCloth' r = RedCloth.new("this is a *test* of _using RedCloth_") puts r.to_html
  • 19. Installing a More Complex Gem You may want to install “hpricot” in specific source for latest version gem install hpricot --source code.whytheluckystiff.net
  • 20. Upgrading and Uninstalling Gems Update all of your currently installed gems gem update Uninstall gems “feedtools” gem uninstall feedtools $ gem uninstall rubyforge Uninstall all gem versions “rubyforge”
  • 21.  
  • 22. Thank-you for attending Feel free to join at http ://groups.google.com/group/khmertech/ KhmerTech

Editor's Notes

  • #2: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #3: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #4: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #5: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #6: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #7: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #8: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #9: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #10: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #11: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #12: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #13: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #14: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #15: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #16: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #17: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #18: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #19: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #20: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #21: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #22: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #23: 06/28/09 11:21 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.