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/scottcreynolds/ac1b5c8d96de0c91bf7c/download | |
# Run it from your terminal with: | |
# ruby ruby_phone_format.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
def apple_picker(array) | |
apples_etc = array.collect { |element| element if element == "apple"} | |
apples_etc.compact | |
end | |
def apple_picker(array) | |
array.select {|element| element == "apple"} | |
end | |
# select returns an array of the original elements that make block evaluate to true, while |
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
movie_collection = { "horror" => ["Kindergarten Cop", "Psycho", "Last House on the Left"], | |
"comedy" => ["Beverly Hills Cop", "Jackass"], | |
"fantasy" => ["The Hobbit", "Willow", "The Princess Bride"]} | |
recipes = { "bolognese sauce" => ["olive oil", "onion", "garlic", "tomato", "basil", "oregano"], | |
"omlette" => ["eggs", "milk", "cheese"], | |
"chicken adobo" => ["chicken", "vinegar", "onions", "garlic", "ginger", "soy sauch"]} | |
user_profiles = { "Jordan" => { "favorite colors" => ["red", "yellow", "blue"], | |
"personal_essays" => ["essay 1", "essay 2", "essay 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
def reverse_each_word(sentence) | |
words = sentence.split | |
back_words = words.collect { |word| word.reverse } | |
back_words.join(" ") | |
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
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] | |
}, | |
:fall => { | |
:thanksgiving => ["Turkey"] |
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 take_a_number(deli, person) | |
deli << person | |
deli.length | |
end | |
def now_serving(deli) | |
puts "Currently serving #{deli.first}" | |
deli.shift | |
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
game = { | |
:home => { | |
:name => "Wu-Tang Clan", | |
:colors => ["Black", "Yellow"], | |
:players => [ | |
{ :name => "Method Man", | |
:number => 6, | |
:shoe_size => 10, | |
:stats => { | |
:points => 49, |
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 Array | |
def version_sort | |
self.sort_by do |file| | |
file.scan(/\d+|[a-z]*/).map { |el| el.to_i } | |
end | |
end | |
end | |
filenames = [ | |
"foo-1.10.2.ext", |
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
# tower_of_hanoi.rb | |
a = [1,2,3,4] | |
b = [] | |
c = [] | |
# Move the disks from one peg to another following the rules of Hanoi. | |
# | |
# number_of_disks - the total number of disks | |
# from - the starting peg |
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
# create a method called create_groups that, given an array of student names, | |
# a group size, and a number of groups, will return an array of groups of | |
# of students with no student in adjacent groups | |
def create_groups(students, group_size, num_of_groups) | |
out_of_order = students.shuffle | |
groups = [] | |
index = 0 | |
num_of_groups.times do | |
group = [] | |
group_size.times do |