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 Deck | |
SUITS = %w(hearts clubs spades diamonds) | |
RANKS = %w(ace two three four five six seven | |
eight nine ten jack queen king) | |
... | |
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 Deck | |
... | |
protected | |
def all_ranks | |
RANKS.map.with_index {|rank, value| Rank.new(rank, value) } | |
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
class Deck | |
... | |
protected | |
def build_deck | |
all_ranks.flat_map {|rank| SUITS.flat_map {|suit| Card.new(rank,suit) } } | |
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
Rank = Struct.new(:rank, :value) do | |
def to_s; rank; end | |
end | |
Card = Struct.new(:rank, :suit) do | |
def to_s; "#{rank} of #{suit}"; end | |
end | |
class Deck | |
SUITS = %w(hearts clubs spades diamonds) |
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
blackjack_deck = Deck.new(8) | |
poker_deck = Deck.new |
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 update | |
if (params[:user][:password].blank? && params[:user][:password_confirmation].blank?) | |
params[:user].delete(:password) | |
params[:user].delete(:password_confirmation) | |
end | |
if params[:user][:photo_attributes] | |
Photos::Manipulation.update_resource_photo(current_user.photo || Photo, params[:user][:photo_attributes], current_user) | |
current_user.photo.try(:reload) |
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
if (params[:user][:password].blank? && params[:user][:password_confirmation].blank?) | |
params[:user].delete(:password) | |
params[:user].delete(:password_confirmation) | |
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
module UserPasswordHashCleaner | |
extend self | |
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
module UserPasswordHashCleaner | |
extend self | |
end | |
require 'minitest/autorun' | |
describe UserPasswordHashCleaner do | |
subject { UserPasswordHashCleaner } | |
describe "call(params)" do |
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
module UserPasswordHashCleaner | |
extend self | |
def call(params) | |
return {} if params.nil? | |
end | |
end | |
require 'minitest/autorun' |