ruby
DESCRIPTION
Ruby – Scripting language, dynamic and object orientedTRANSCRIPT
-
RubyProgrammingLanguage
RubyScriptinglanguage,dynamicandobjectoriented
Allowsrapiddevelopmentandrapidprototypesofsoftware
Consistsofusefulstringoperationsandregularexpressions
EverythinginRubyisanobject
Hasautomaticgarbagecollection
Instantfeedbackwhendeveloping
MultipleOSsupportandopensource
-
RubyProgrammingLanguage
History
BornFeb23,1993YukihiroMatzMatsumoto
Ruby0.95announcedDec21,1995OO,Inheritance,iterators,exceptionhandling,garbagecollection
Ruby1.0releasedDec25,1996
Ruby1.31999AfteritsreleaseanEnglishRubymailinglistwascreated
RubyonRails2005MVCwebframeworkcodedwithRuby
Ruby1.9.1Latestversion
-
RubyProgrammingLanguage
Philosophy
Rubyissimpleinappearance,butisverycomplexinside,justlikeourhumanbodyMatz
POLSPrincipleofLeastSurpriseDesignthelanguagesoexperiencedProgrammershaveminimalconfusion.
-
RubyProgrammingLanguage
RubyinAction
ToexecuteRubycodeusetheIRB(interativerubyinterpreter)orfromaTerminaltype:%rubyfilename.rb
ClassicHelloWorldexampleusingirb::
c@claptop:~$irbirb(main):001:0>puts"HelloWorld"HelloWorld=>nil
Usingafilenamedhello.rb
c@claptop:~/Documents/cs183$rubyhello.rbHelloWorld
-
RubyProgrammingLanguage
RubyinBasics
Output:printrubyrocksputsrubyrocks//insertsaCRandend
Functions:defwelcome(name)
putshey#{name}end
:Functionswithmultiplereturnvalues:
defget_cost_mpgcost=20mpg=20Returncost,mpg
endHum_cost,Hum_mpg=get_cost_mpg
-
RubyProgrammingLanguage
RubyinBasics
Variables:Globalsprefixwitha'$'Instancevarsprefixwitha'@'
Comments:use'#'
SinceeverythinginRubyisanobjectwecanapplymethods:1.5.floor()=>1
if(x>7&&x
-
RubyProgrammingLanguage
RubyinBasics
grade=10school=casegradewhen0..5"elementary"when6..8"middleschool"when9..12"highschool"else"college"end
.
foriin1..4puts"hi#{i}"end
ArrayLoopusing'each'
animals=%w(lionstigersbears)animals.each{|kind|printkind}
-
RubyProgrammingLanguage
RubyClass
classPersondefinitialize(fname,lname)@fname=fname@lname=lnameenddefto_s"Person:#@fname#@lname"endendperson=Person.new("Augustus","Bondi")printperson
-
RubyProgrammingLanguage
RubyFileIO
Performafile>stringoperation:Easyas:file=File.new("t1.php")mytext=file.read
Breakdownthefileintoanarrayoflines:lines=IO.readlines("data.txt")putslines[0]#printsthefirstline
Outputfilecontents:IO.foreach("data.txt"){|line|putsline}
-
RubyProgrammingLanguage
RubyHTMLExtractorExample
require'openuri'open('http://www.soe.ucsc.edu/classes/cmps183/Spring10/'){|f|printf.read}
BenefitsofRuby:Cleancode,Easytolearn,Documentionandsupport,OpenSource,OO
DrawbacksofRuby:Interpreted{Read;Eval;Loop;}Performance
-
RubyProgrammingLanguage
Links
http://www.fincher.org/tips/Languages/Ruby/
http://www.rubylang.org/en/about/
http://www.rubylang.org/en/documentation/quickstart/
http://en.wikipedia.org/wiki/Ruby_%28programming_language%29
http://articles.sitepoint.com/article/learnrubyonrails
http://www.fincher.org/tips/Languages/Ruby/http://www.ruby-lang.org/en/about/http://www.ruby-lang.org/en/documentation/quickstart/http://en.wikipedia.org/wiki/Ruby_%28programming_language%29http://articles.sitepoint.com/article/learn-ruby-on-rails - Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12