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 Array | |
def new_each | |
0.upto(self.length-1) do |index| | |
yield(self[index]) | |
end | |
end | |
end |
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 Array | |
def new_count | |
self.inject(0) { |accum , i| yield(i) ? accum += 1 : accum } | |
end | |
end | |
# Exercise for the reader: Figure out why my original idea: "self.inject(0) { |accum , i| accum += 1 if yield(i) }" is not completely valid |
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
module Mark_twain | |
def mark_twain | |
mark_twain_helper(self, []) | |
end | |
def mark_twain_helper(str, accum_ar) | |
if str.split.length == 1 | |
accum_ar << "Final draft: #{str}." | |
accum_ar | |
else |
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 game(ar) | |
throw1 = ar[0][1].downcase | |
throw2 = ar[1][1].downcase | |
if %w{ rs pr sp }.include?(throw1 + throw2) | |
return ar[0] | |
elsif %w{ sr rp ps}.include?(throw1 + throw2) | |
return ar[1] | |
else | |
"It's a Tie!" |
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
require 'jumpstart_auth' | |
require 'bitly' | |
class JSTwitter | |
attr_reader :client | |
def initialize | |
puts "Initializing" | |
@client = JumpstartAuth.twitter | |
end |
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
module Anagram | |
attr_reader :word_dict | |
def anagrams | |
@word_dict = {} | |
self.each do |str| | |
puts str | |
sorted_str = str.chars.sort.join | |
if @word_dict[sorted_str] == nil | |
@word_dict[sorted_str] = [str] | |
else |
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 Array | |
def pad!(min_size, value = nil) | |
self.concat( Array.new(min_size - self.length, value)) if self.length < min_size | |
self | |
end | |
def pad(min_size, value = nil) | |
self.dup.pad!(min_size,value) | |
end | |
end |
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 SudokuBoard | |
def initialize(board_str) | |
@board = board_str.split("").map { |value| Cell.new(value.to_i) } | |
@groups = [] | |
(generate_rows + generate_cols + generate_grids).each do |group_member_indices_ar| | |
group_cell_members = group_member_indices_ar.map { |index| @board[index] } | |
@groups << Group.new(group_cell_members) | |
end | |
puts to_s |
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
require 'rspec' | |
require 'simplecov' | |
require './task.rb' | |
SimpleCov.start | |
require './list.rb' | |
describe Todo::List do | |
before(:each) do | |
@file_path = './spec_todo.txt' |
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
require 'rspec' | |
require 'simplecov' | |
SimpleCov.start | |
require './task.rb' | |
describe Todo::Task do | |
before(:each) do | |
@time = Time.now | |
Time.stub(:now).and_return(@time) |