資源描述:
《Ruby, Essential.pdf》由會員上傳分享,免費在線閱讀,更多相關內容在學術論文-天天文庫。
1、#30CONTENTSINCLUDE:nRubyLanguageOverviewnSimpleRubyExamplesnIRBEssentialRubynRubyGemsnRubyLanguageReferenceTablesByMelchiorBrislingerandPeterCoopermVisitrefcardz.conHotTipsandMore...AbOUTRUbySImpLERUbyExAmpLESRubyisaneasy-to-learn,dynamic,object-orientedprogrammingDesp
2、itebeinganobject-orientedlanguage,itisnotnecessarylanguagewithdynamictypingandautomaticmemorytouseexplicitlyobject-orientedsyntaxwithinabasicRubymanagement.Whileobject-orientedatheart,itprovidesprogram.Whileeverythingworksonobjects(andmethodsfacilitiesforproceduralandf
3、unctionalprogrammingaswellascalleduponthoseobjects)behindthescenes,youcanwriteaprogramassimplyasthis:extensivesupportforintrospectionandmeta-programming.Ruby’scoreAPI,extensivestandardlibrary,andthousandsofdeffib(i)GetMoreRefcardz!high-qualityexternallibrariesmakeitsui
4、tableformanydifferentifi.zero?0programmingtasksinmultipledisciplines(keyexamplesbeingelsifi==1networkprogramming,Webapplications,shellscripts,data1elseprocessing,andtextmanipulation).fib(i-2)+fib(i-1)RubyisalreadyinstalledonMacOSXandmanyLinuxendenddistributions.ForWind
5、owstheeasiestwaytoinstalleverythingnecessaryistheRubyInstaller(http://rubyinstaller.rubyforge.org).putsfib(10)Thisscriptprintstoscreenthe10thnumberintheFibonacciThisrefcardprovidesaquickreferencetolanguageelementssequence.Itdefinesamethodcalledfibthatreturnstheandmanyi
6、mportantAPIfunctionsforquicklookup.relevantresultfromasimpleif/elsif/elseexpression.Notetheuseofstandardequalitysyntax(==),addition(+),subtractionRUbyLANgUAgEOvERvIEw(-),andmethodcalling(fib(10)),butalsonotethepossibilityofusingmethodsinsomewhatidiomaticways(i.zero?rat
7、herRubyisconsideredtobea“pure”object-orientedlanguagethani==0—thoughthelatterwouldalsowork).TheuseofbecausealmosteveryconceptwithinRubyisobject-orientedi.zero?demonstratescallingamethoduponanobject(wherezone.cominsomesense.Yukihiro“Matz“Matsumoto,Ruby’screator,iistheob
8、ject,andzero?isthemethod).d.wantedtodevelopalanguagethatoperatedonthe“principleofleastsurprise”meaningthatcodeshouldb