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 add_two(array) | |
array.map { |item| "#{item} + 2 = #{ item+2 }" } | |
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
def merge_us(hash1, hash2) | |
hash1.merge(hash2) | |
end | |
def my_keys(hash) | |
hash.keys | |
end | |
def do_i_have?(h ={},keys) | |
h.keys.sort == keys.sort |
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 Title | |
attr_reader :string | |
def initialize(string) | |
@string = string | |
end | |
def fix | |
# A neat Ruby trick for making an array of strings | |
# Equivalent to: ['a', 'and', 'the', 'of'] |
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 add_item!(item, list) | |
list << item unless list.include?(item) | |
list | |
end | |
def remove_item!(item, list) | |
list.delete(item) | |
list | |
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
class ArrayModifier | |
attr_reader :array | |
def initialize(array) | |
@array = array | |
end | |
def exclaim | |
new_array = [] |
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 President | |
attr_accessor :name, :age | |
def initialize(name, age) | |
@name, @age = name, age | |
end | |
def citizenship | |
self.class.citizenship | |
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
class ArrayModifier | |
attr_reader :array | |
def initialize(array) | |
@array = array | |
end | |
def exclaim | |
new_array = [] |
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
mkdir ~/bin | |
touch ~/.bash_profile | |
echo 'export PATH="~/bin:$PATH"' >> ~/.bash_profile | |
echo "export EDITOR='subl -w'" >> ~/.bash_profile | |
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl | |
source ~/.bash_profile |
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 save_with_initial_vote | |
ActiveRecord::Base.transaction do | |
saved = self.save | |
self.create_vote | |
saved | |
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
import random | |
def show_guesses(): | |
guesses.append(guess) | |
print(str(guesses) + " {} more out of 5.".format(5 - len(guesses))) | |
def show_help(): | |
print("Guess a number between '1' and '10'") | |
print("'DONE' quits and 'HELP' displays this help.") |