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
#!/usr/bin/env ruby | |
require "rubygems" | |
gem "minitest" | |
require "minitest/autorun" | |
require "minitest/pride" | |
class Palindrome | |
def search string | |
@array = string.gsub(/[^0-9a-z ]/i, '').gsub(' ', '').downcase.split '' | |
@palindromes = [] |
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 Dog | |
attr_accessor :age | |
def dog_years | |
return "Gimme a human age first, damnit..." unless @age | |
@dog_years = 15 | |
@dog_years += 9 if @age > 1 | |
@dog_years += (@age - 2) * 4 if @age > 2 | |
@dog_years | |
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 self.something | |
:red | |
end | |
something #=> :red | |
defined? something #=> "method" | |
something = :blue # then local variable hijacks something, oh noes |
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 'set' | |
symptoms = Set["bezoars", "turning purple", "jaundice"] | |
gvhd = Set["jaundice", "bloody diarrhea", "skin inflammation"] | |
"whipple" if gvhd.proper_subset? symptoms |
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
symptoms = ["bezoars", "turning purple", "jaundice", "bloody diarrhea", "skin inflammation"] | |
gvhd = ["jaundice", "bloody diarrhea", "skin inflammation"] | |
gvhd.all? { |symptom| symptoms.include? symptom } |
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 x | |
:a_method | |
end | |
x # => :a_method | |
x = :a_variable | |
x # => :a_variable |
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 'minitest/autorun' | |
require 'minitest/pride' | |
class Integer | |
def ordinalize | |
suffix = if (abs % 100).between? 11, 13 | |
'th' | |
else | |
case abs % 10 | |
when 1; 'st' |
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 String | |
def say | |
puts self | |
end | |
end | |
%w[cats vanilla trees].each(&:say) | |
#=> | |
cats |
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 puts(*a) | |
$stdout.puts(*a) | |
nil | |
end | |
def puts(*args) | |
if args.empty? | |
write DEFAULT_RECORD_SEPARATOR | |
else | |
args.each do |arg| |
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 fun(&block) | |
@block = proc { yield } | |
end | |
fun { puts "How is this fun?" } | |
@block.call #=> How is this fun? |