This file contains 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
# Start with the following collected data on NYC pigeons. | |
pigeon_data = { | |
:color => { | |
:purple => ["Theo", "Peter Jr.", "Lucky"], | |
:grey => ["Theo", "Peter Jr.", "Ms .K"], | |
:white => ["Queenie", "Andrew", "Ms .K", "Alex"], | |
:brown => ["Queenie", "Alex"] | |
}, | |
:gender => { |
This file contains 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 my_each(array) | |
i = 0 | |
while i < array.length | |
raise (yield(array[i])).inspect | |
i+=1 | |
end | |
array | |
end | |
array = [1, 2, 3] |
This file contains 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
# Write a method that returns whether a given letter is a vowel, using if and elsif | |
def is_vowel1(letter) | |
letter.downcase! | |
if letter == "a" | |
return true | |
elsif letter == "e" | |
return true | |
elsif letter == "i" | |
return true |
This file contains 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 my_each(array) | |
i = 0 | |
while i < array.length | |
raise (yield(array[i])).inspect | |
i+=1 | |
end | |
array | |
end | |
array = [1, 2, 3] |
This file contains 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
# Download this file: | |
# https://gist.github.com/aviflombaum/872638777f7511d2a30a/download | |
# Run it from your terminal with: | |
# ruby ruby.basics.rb | |
# (Just make sure you are in the right directory) | |
# ====================================== | |
# Ignore All This Code | |
# ====================================== |
This file contains 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 Person | |
attr_accessor :name, :birthday, :hair_color, :eye_color, :height, :weight, :handed, | |
:complexion, :t_shirt_size, :wrist_size, :glove_size, :pant_length, :pant_width | |
def initialize(attributes) | |
attributes.each do |key, value| | |
self.instance_variable_set("@#{key}", value) | |
end | |
end |
This file contains 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 'sqlite3' | |
class Student | |
attr_accessor :name, :twitter, :linkedin, :facebook, :website, :id | |
@@db = SQLite3::Database.new 'students.db' | |
@@students = [] | |
def initialize |
This file contains 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 TriangleError < Exception | |
end | |
class Triangle | |
attr_accessor :side1, :side2, :side3 | |
def initialize(side1, side2, side3) | |
@side1 = side1 | |
@side2 = side2 | |
@side3 = side3 |
This file contains 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
songs = { | |
"The Phoenix - 1901" => "https://www.youtube.com/watch?v=gvss3uhSKjw", | |
"Tokyo Police Club - Wait Up" => "https://www.youtube.com/watch?v=ZAxRozTgoXM", | |
"Sufjan Stevens - Too Much" => "https://www.youtube.com/watch?v=K0g7R3xqdcM", | |
"The Naked and the Famous - Young Blood" => "https://www.youtube.com/watch?v=0YuSg4mts9E", | |
"(Far From) Home - Tiga" => "https://www.youtube.com/watch?v=jTwQbc9kkUc", | |
"The Cults - Abducted" => "https://www.youtube.com/watch?v=9i1MXHGB8g0", | |
"The Phoenix - Consolation Prizes" => "https://www.youtube.com/watch?v=gnkVUReUVpQ" | |
} |
This file contains 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 Anagram | |
attr_accessor :word | |
def initialize(word) | |
@word = word | |
end | |
def match(words_array) | |
words_array.select {|element| element.chars.sort == @word.chars.sort} | |
end |