This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ranges | |
range_1 = (1..10) # includes the last | |
p range_1 | |
range_2 = (1...10) # does not include the last | |
p range_2.to_a | |
# Arrays | |
movies_stars = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What is an acronym: | |
# WTF => what the f*ck | |
# CIA => central intelligence agency | |
# FBI => federal bureau of investigation | |
# Pseudocode: | |
# 1) we start with a String | |
# 2) split the sentence into words => Array | |
# delete ["of", "the", "a"] | |
# 3) get the first letter of each word #each/map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Data Types / Built-in Objects | |
"Hello" # String | |
'Hello' # String | |
4 # Integer | |
4.3 # Float | |
false # Boolean | |
p [3, "Hello", 3.4, true] # Array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'person' | |
# ARRAY CRUD | |
# CREATE | |
# index. 0. 1. ... | |
musicians = ["paul", "ringo"] | |
p musicians | |
# READ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student | |
attr_reader :first_name, :last_name, :nationality, :gender | |
#. first_name, last_name ... | |
def initialize(params = {}) | |
@first_name = params[:first_name] | |
@last_name = params[:last_name] | |
@nationality = params[:nationality] | |
@gender = params[:gender] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#. 0. 1 | |
students = [ | |
["john", 28], | |
["mary", 22], | |
["peter", 18] | |
] | |
# TODO: transform student into an array of hashes | |
students_hash = students.map do |student| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypt(sentence, permutation_level = -3) | |
return "" if sentence.empty? | |
alphabet = ("A".."Z").to_a | |
# 1. Split string into letters | |
letters = sentence.upcase.split("") | |
# 2. Go through each letter | |
result = "" | |
# letters.each do |letter| | |
# # 3. Find index in list of letters | |
# letter_index = alphabet.index(letter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# YIELD | |
def bigcount | |
(0..100000000).sort | |
end | |
def timer(callback) | |
start_time = Time.now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def acronymize(string) | |
# TODO: write a method that returns | |
# the acronym for the given string | |
# 1. Split the sentence into words | |
# 2. Grab the first letter of each word | |
# 3. Capitalize it | |
# 4. Join the first letters together | |
# 5. return the result | |
# gsub: string to replace , replace with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add remote: true to form | |
<%= simple_form_for @model, remote: true do |f| %> | |
# ... | |
<%= f.button :submit %> | |
<% end %> | |
# controller receives ajax request | |
def create | |
# do something |