Presentation is loading. Please wait.

Presentation is loading. Please wait.

Let's Learn Ruby AQAP As Quickly As Possible!.  Run the interactive ruby shell – irb  Suggest using Netbeans – download ALL Running Ruby Code 2.

Similar presentations


Presentation on theme: "Let's Learn Ruby AQAP As Quickly As Possible!.  Run the interactive ruby shell – irb  Suggest using Netbeans – download ALL Running Ruby Code 2."— Presentation transcript:

1 Let's Learn Ruby AQAP As Quickly As Possible!

2  Run the interactive ruby shell – irb  Suggest using Netbeans – download ALL Running Ruby Code 2

3 2 + 6 22 / 4  5 Float(22)/4 22.0 / 4 3 * 3 3 ** 3 big_number = 1_000_000_000 (underscores not required and can go anywhere allowed to make it more readable – commas hard to see) Simple Ruby Number Objects 3

4 Math.sqrt( 9 ) Math.methods 9.methods  will tell you what methods can be used with 9 27.class  will tell you what class 27 belongs to (Fixnum) 3.times { print "Ho! " } 1.upto( 5 ) { |i| puts i }  defines i as the iterator variable termed a “code block” Anonymous delegate given the name i Ruby Number Methods 4

5 one = "1" two = "2" one + two  string concat, right? Integer( one ) + Integer( two )  casts and then adds 12.to_s  calls to string method, but wants you to request conversion print "Happy ", 12.to_s, "th Birthday!" puts "Happy ", 12.to_s, "th Birthday!" puts "Happy " + 12 + "th Birthday!" Number Conversions 5

6 a1 = "this is a string\n”  evaluate backslash and contents of #{} inside of the string. Termed string interpolation a2 = 'and so is this\n‘  will see the \n as no evaluation is done print a1 print a2 answer = “joy” puts "The meaning of life is #{answer}" puts "There's #{24*60*60} seconds in a day" Ruby String Objects 6

7 formatted_text = < { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/13/3818725/slides/slide_7.jpg", "name": "formatted_text = <

8 String.methods.sort  sorted list of String methods formatted_text.size  number of characters formatted_text.downcase  lowercase formatted_text.upcase  uppercase formatted_text.capitalize!  ! means to actually change the object in place (rather than return a changed copy) formatted_text.reverse  reverses all characters formatted_text.empty?  boolean indicated by ? only used in method names (not variables) Ruby String Methods 8

9 song_lines = formatted_text.to_a  to array (1..10).to_a  [1,2,3,4,5,6,7,8,9,10] from a range (denoted..) (‘a’..’e’).to_a  [“a”, “b”, “c”, “d”, “e”] print song_lines[1] print song_lines[5] print song_lines[99]  Gives nil if used when out of range, will add to array if assign outside of range. print song_lines print formatted_text song_lines.class  Array formatted_text.class  String Working with Ruby Strings 9

10 Same variable can hold any type at different times… a = 42 puts a a = "The Ruby Programming Language" puts a a = 1.8 puts a What About Variable Type? 10

11  Everything - numbers, strings, data structures, Class itself etc. - is an object  Methods are invoked using the dot (".") notation  Variables are dynamically created as needed (problems with typos), but will tell you during execution if you access something without a value.  The traditional notion of a variable's "type" is not something the Ruby programmer concerns themselves with (too much) Ruby So Far 11


Download ppt "Let's Learn Ruby AQAP As Quickly As Possible!.  Run the interactive ruby shell – irb  Suggest using Netbeans – download ALL Running Ruby Code 2."

Similar presentations


Ads by Google