The Complete Ruby on Rails Developer Course

S3E45

Time to take notes!

  • What is Rails?
  • Who is DHH
  • What are the components of a Rails Applications?
  • what are gems?

Arrays and Iterators

Array, created by including elements within square brackets:

a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

arrayname.empty?

arrayname.reverse! # use ! at the end to change the original array

arrayname.shuffle # to shuffle elements in hash

arrayname.push(30) # will append new element 30 to the end of array

arrayname << 25 # << know as shovel operator will also append new element to the end of an array

arrayname.unshift("someelement") # will add element "someelement" to the beginning of the array (插入元素到陣列最前面)

arrayname.pop # will remove the last element of the array and return (取出最後一個元素並回傳,會修改到原始陣列)

arrayname.uniq! # will remove all the duplicate elements in the original array. (移出重複的元素)

HASH

$ myhash = {a: 1, b: 2, c: 3}
$ => {:a=>1. :b=>2, :c=>3}

$ myhash[:c] # call symbol :c
$ => 3

$ myhash[:name] = "Steven"

results matching ""

    No results matching ""