Skip to content

Instantly share code, notes, and snippets.

@shoota
Last active August 29, 2015 14:00
Show Gist options
  • Save shoota/11022080 to your computer and use it in GitHub Desktop.
Save shoota/11022080 to your computer and use it in GitHub Desktop.
ruby tutorial at dot install
p "---array operator---"
# array object
sales = [5,8,4]
# replace
sales[0...2]=[1,2]
p sales # [1,2,4]
# insertion
# -- (replace 0 objects after index 1) === insertion
sales[1, 0] = [10,11,12]
p sales # [1, 10,11,12, 2, 4]
# deletion
# -- (replace to empty array) === deletion
sales[0, 2] = []
p sales # [11, 12, 2, 4]
p "---array method---"
p sales.size
p sales.sort
p sales.sort.reverse
p sales.push(100)
p sales << 101 << 102
# hash (key value)
p "---hash operator---"
sales1 = {"taguchi" => 200, "fkoji" => 300}
p sales1["taguchi"]
sales2 = {:taguchi => 100, :fkoji => 400}
p sales2[:taguchi]
sales3 = {taguchi: 1000, fkoji: 100}
p sales3[:taguchi]
p "---hash method---"
p sales1.size
p sales1.keys
p sales1.values
# key string is not equql symbol.
p sales1.has_key?(:taguchi)
p sales2.has_key?(:taguchi)
p sales1.has_key?("taguchi")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment