Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created March 3, 2020 01:07
Show Gist options
  • Save harrisonmalone/26bec0bfaa09e39c1df7ebffcc296386 to your computer and use it in GitHub Desktop.
Save harrisonmalone/26bec0bfaa09e39c1df7ebffcc296386 to your computer and use it in GitHub Desktop.
# def random_method(num, num2)
# num * 10
# # => 100
# end
# p random_method(10, 100)
# while true
# p "hello"
# end
# until false
# p "hello"
# end
# i = 1
# while i < 4
# puts i
# i = i + 1
# end
# good_music = ["rap", "country", "pop"]
# for genre in good_music
# print genre
# # something
# break if genre == "country"
# print ","
# end
# "string"
# 1
# 1.1
# true
# [1,2,3]
# nil
# .class
# greeting = :hello
# p greeting
# b = "my_string"
# a = "my_string"
# p a.object_id
# p b.object_id
# c = :hello
# d = :hello
# p c.object_id
# p d.object_id
# what is a data structure?
# - where you store data, more than one piece of data
# - one piece of data just goes in a single variable
# - arrays, is a data structure for similar types of data
# colors = ["red","ff0000" "blue", "green"]
# hash is another data structure
# old syntax
# red = {
# :color_name => "red",
# :hex => "ff0000"
# }
# new syntax
red = {
color_name: "red",
hex: "ff0000",
primary_color: true
}
# purple = {
# color_name: "purple",
# hex: "ff00ff",
# primary_color: false
# }
# arr = [1,2,3]
# p arr[2]
# => 3
purple = {
color_name: "purple",
hex: "ff00ff",
primary_color: false,
things: [
"rainbow",
"grapes",
"fremantle dockers"
]
}
# p purple[:things]
# numbers = { 1 => "one", "2" => "two" }
# p numbers
# numbers = { 1 => "one", "2" => "two" }
# numbers.each do |key, value|
# p key
# end
# numbers = ["one", "two", "three", "four"]
# counter = 1
# numbers.map! do |number|
# number = number + counter.to_s
# counter = counter + 1
# number
# end
# p numbers
# => ["one1", "two2", "three3", "four4"]
# .each
def my_each(array)
index = 0
while index < array.length
yield(array[index])
index = index + 1
end
return "hello"
end
result = my_each([1,2,3]) do |number|
puts number
end
p result
# => "hello"
# CRUD
# create
# read
# update
# delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment