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
<<-HOW_TO_USE | |
Paste this line into any ruby console if you dare: | |
require 'net/http'; url = 'https://gist.githubusercontent.com/seanlerner/092ce4caec301d758b524adbd715242a/raw/seans-ruby-helpers.rb'; eval(Net::HTTP.get(URI(url))) | |
HOW_TO_USE | |
def exception_message(exception) | |
if exception.message.include?("undefined method `include'") |
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 flatten_array(input) | |
input.to_s.gsub(/\[|,|\]/, ' ').split.map(&:to_i) | |
end | |
# TEST 1 | |
input = [[1, 2, [3]], 4] | |
expected = [1, 2, 3, 4] | |
actual = flatten_array(input) | |
puts |
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 GildedRose | |
attr_reader :name, :days_remaining, :quality | |
∞ = Float::INFINITY | |
CHEESE = { | |
'Normal Item' => { -∞..0 => -2, 1..∞ => -1 }, | |
'Aged Brie' => { -∞..0 => 2, 1..∞ => 1 }, | |
'Conjured Mana Cake' => { -∞..0 => -4, 1..∞ => -2 }, |