presidents=["John","Richard","Gerald","Ronald","George","William"]; |
presidents= %w[ John Richard Gerald Ronald George William]; |
order_date=Date.today() shirt_information=[14.5,"Long",32,order_date] |
irb(main):003:0> shirt_information[2] => 32 irb(main):004:0> shirt_information.at(2) => 32 |
irb(main):005:0> shirt_information[-3] => "Long" |
irb(main):013:0> shirt_information => [14.5, "Long", 32, #<Date: 4907585/2,0,2299161>] irb(main):014:0> shirt_information[1]="Medium" #change shirt length => "Medium" irb(main):015:0> shirt_information[4]=49.99 #add shirt cost => 49.99 irb(main):016:0> shirt_information => [14.5, "Medium", 32, #<Date: 4907585/2,0,2299161>, 49.99] |
irb(main):019:0> shirt_information => [14.5, "Long", 32, #<Date: 4907585/2,0,2299161>, 49.99] irb(main):020:0> shirt_dimensions = shirt_information[0,3] => [14.5, "Long", 32] irb(main):021:0> shirt_order = shirt_information[2..5] => [32, #<Date: 4907585/2,0,2299161>, 49.99] irb(main):030:0> shirt_information[-3,2] => [32, #<Date: 4907585/2,0,2299161>] |
irb(main):001:0> test_array=["zero", "one", "two", "three", "four"] => ["zero", "one", "two", "three", "four"] irb(main):002:0> #starting at the second element, replace the next two elements with a single element irb(main):003:0* test_array[1,2]=1 => 1 irb(main):004:0> test_array => ["zero", 1, "three", "four"] irb(main):005:0> #insert a new element after the second one (zero as a second parameter indicates "insert") irb(main):006:0* test_array[2,0]=2 => 2 irb(main):007:0> test_array => ["zero", 1, 2, "three", "four"] irb(main):008:0> #add an array of elements after element 5 irb(main):009:0* test_array[5,0]=[5,6,7] => [5, 6, 7] irb(main):010:0> test_array => ["zero", 1, 2, "three", "four", 5, 6, 7] irb(main):011:0> #replace elements in the index range of 3..4 with the array assigned irb(main):012:0* test_array[3..4]=[3,4] => [3, 4] irb(main):013:0> test_array => ["zero", 1, 2, 3, 4, 5, 6, 7] |
irb(main):033:0> shirt_information => [14.5, "Long", 32, #<Date: 4907585/2,0,2299161>, 49.99] irb(main):034:0> pant_information=[34,32,59.99,order_date] => [34, 32, 59.99, #<Date: 4907585/2,0,2299161>] irb(main):035:0> shirt_information + pant_information => [14.5, "Long", 32, #<Date: 4907585/2,0,2299161>, 49.99, 34, 32, 59.99, #<Date: 4907585/2,0,2299161>] irb(main):036:0> shirt_information * 2 => [14.5, "Long", 32, #<Date: 4907585/2,0,2299161>, 49.99, 14.5, "Long", 32, #<Date: 4907585/2,0,2299161>, 49.99] irb(main):037:0> array1 = [2,4,6,8,10] => [2, 4, 6, 8, 10] irb(main):038:0> array2=[3,6,9] => [3, 6, 9] irb(main):039:0> array1 - array2 => [2, 4, 8, 10] |
holidays={"New Year"=>Date.parse("2006-01-02"), "MLB Birthday"=> Date.parse("2006-01-16"), "Washington Birthday"=>Date.parse("2006-02-20"), "Memorial Day"=>Date.parse("2006-05-29"), "July 4th"=>Date.parse("2006-07-05")} |
irb(main):004:0> holidays["Memorial Day"] => # irb(main):005:0> holidays["Memorial Day"].to_s => "2006-05-29" |