DOC PREVIEW
CMU ISM 95733 - Internet Technologies

This preview shows page 1-2-3-4-5-6-38-39-40-41-42-78-79-80-81-82-83 out of 83 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 83 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Notes on Ruby From Sebesta's "Programming The World Wide Web"General Notes on Ruby(1)General Notes on Ruby(2)Interactive EnvironmentMore interactive RubyThe Math ModuleNon-Interactive RubyFun with newlinesConverting CaseTesting EqualityReading The KeyboardReading IntegersConditions (1)Conditions (2)Conditions (3)Conditions (4)Conditions (5)Conditions (6)Case/When with RangeValue of Case/When (1)Value of Case/When(2)WhileUntilArrays(1)Arrays(2)Arrays(3)Arrays and Ranges(1)Arrays and Ranges(2)HashesHashes IndexingHashes Adding & DeletingHashes Taking The KeysMethodsMethods Local VariablesScalers Are Pass By ValueArrays and Hashes Are Pass By ReferenceClassesSimple InheritanceModulesCode BlocksPattern MatchingRegular ExpressionsRuby On RailsModel View ControllerModel View ControllerModel View ControllerRails ToolsRails DirectoriesThree Examples From SebestaUsing NetbeansCreate an RoR ProjectSelect MySQLModels Views and ControllersRun And Visit RailsGenerate A ControllerModify The Default ControllerEnter The ViewRun And Visit The ApplicationProcessing FormsSelect DatabaseSelect Rails VersionFrom Project Generate ControllerThe First Action Method is the_formAdd A ViewAdd A ViewModify The Controller(1)Modify The Controller(2)result.rhtml (1)result.rhtml (2)Initial Visit on the_formForm Submitted to resultThe Model (1)The Model (2)The Model (3)The Model (4)Convention Over ConfigurationModel Based ValidationRelationships(1)Relationships(2)Relationships(3)Relationships(4)Relationships(5)95-733 Internet Technologies 1 Internet TechnologiesRuby andRuby on Rails95-733 Internet Technologies 2Notes on Ruby From Sebesta's "Programming The World Wide Web" Designed in Japan by Yukihiro Matsumoto  Released in 1996 Designed to replace Perl and Python Rails, a web application development framework , was written in and uses Ruby Ruby is general purpose but probably the most common use of Ruby is Rails Rails was developed by David Heinemeier and released in 2004 Basecamp (project management) is written in RoR95-733 Internet Technologies 3Ruby is a pure object-oriented language.All variables reference objects.Every data value is an object.References are typeless.All that is ever assigned in an assignment statement is the address of an object.The is no way to declare a variable.A scalar variable that has not been assigned a value has the value nil.Ruby has implicit variables.General Notes on Ruby(1)95-733 Internet Technologies 4Three categories of data types - scalars, arrays and hashes Two categories of scalars - numerics and character strings Everything (even classes) is an object Numeric types inherit from the Numeric class Float and Integer inherit from Numeric Fixnum (32 bits) and Bignum inherit from Integer All string literals are String objects The null string may be denoted as " or as '’”. The String class has over 75 methodsGeneral Notes on Ruby(2)95-733 Internet Technologies 5Interactive Environment$irb>> miles = 1000=> 1000>> milesPerHour = 100=> 100>> "Going #{miles} miles at #{milesPerHour} MPH takes #{1/milesPerHour.to_f*miles} hours"=> "Going 1000 miles at 100 MPH takes 10.0 hours"95-733 Internet Technologies 6More interactive Ruby$irb>> miles = 1000=> 1000>> s = "The number of miles is #{miles}"=> "The number of miles is 1000">> s=> "The number of miles is 1000"95-733 Internet Technologies 7The Math Module>> y = Math.sin(0)=> 0.0>> y = Math.sin(Math::PI/2.0)=> 1.095-733 Internet Technologies 8Non-Interactive RubySave as one.rb and run with ruby one.rba = "hi"b = aputs aputs bb = "OK"puts aputs bOutput======hihihiOK95-733 Internet Technologies 9Fun with newlinesa = "He\nllo\n"puts aputs aOutput======HelloHello95-733 Internet Technologies 10Converting Casea = "Hello"a.upcase!puts aputs aOutput======HELLOHELLO95-733 Internet Technologies 11Testing Equalityb = "Cool course" == "Cool course" # same contentputs bb = "Cool course".equal?("Cool course") #same objectputs bputs 7 == 7.0 # same valueputs 7.eql?(7.0) # same value and same typeOutput======truefalsetruefalse95-733 Internet Technologies 12Reading The Keyboardputs "Who are you?"name = gets #include entered newlinename.chomp! #remove the newlineputs "Hi " + name + ", nice meeting you."Interaction===========Who are you?MikeHi Mike, nice meeting you.95-733 Internet Technologies 13Reading Integers#to_i returns 0 on strings that are not integersputs "Enter two integers on two lines and I'll add them"a = gets.to_ib = gets.to_iputs a + bInteraction===========Enter two integers on two lines and I'll add them24695-733 Internet Technologies 14Conditions (1)a = 5if a > 4 puts "Inside the if" a = 2endputs "a == " + a.to_s(10)Output======Inside the ifa == 295-733 Internet Technologies 15Conditions (2)a = 5unless a <= 4 puts "Inside the if" a = 2endputs "a == " + a.to_s(10)Output======Inside the ifa == 295-733 Internet Technologies 16Conditions (3)a = 5if a <= 4 puts "Inside the if" a = 2else puts "a == " + a.to_s(10)endOutput======a == 595-733 Internet Technologies 17Conditions (4)a = 5if a <= 4 puts "Inside the if" a = 2elsf a >= 10 puts "a == " + a.to_s(10) puts "OK"else puts "Neither"endOutput======Neither95-733 Internet Technologies 18Conditions (5)a = 5case awhen 4 then puts "The value is 4"when 5 puts "The value is 5"endOutput======The value is 595-733 Internet Technologies 19Conditions (6)a = 2case awhen 4 then puts "The value is 4"when 5 puts "The value is 5"else puts "OK"endOutput======OK95-733 Internet Technologies 20Case/When with Range a = 4case awhen 4 then # after a match we are done puts "The value is 4"when (3..500) puts "The value is between 3 and 500"else puts "OK"endOutput======The value is 495-733 Internet Technologies 21Value of Case/When (1) year = 2009leap = casewhen year % 400 == 0 then truewhen year % 100 == 0 then falseelse year % 4 == 0endputs leapOutput======false95-733 Internet Technologies 22Value of Case/When(2) year = 2009puts casewhen year % 400 == 0 then truewhen year % 100 == 0 then falseelse year % 4 == 0endOutput======false95-733 Internet Technologies 23Whiletop = 100now = 1sum = 0while now <= top sum = sum + now now += 1 endputs sumOutput======505095-733 Internet Technologies 24Untilj = 100until j < 0 j = j - 1endputs jOutput======-195-733 Internet Technologies 25Arrays(1)a = [1,2,3,4,5]puts a[4]x = a[0]puts xa = ["To","be","or","not","to","be"]j =


View Full Document

CMU ISM 95733 - Internet Technologies

Download Internet Technologies
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Internet Technologies and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Internet Technologies 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?