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 cmd(c) | |
system c | |
end | |
namespace :tddium do | |
desc "post_build_hook" | |
task :post_build_hook do | |
# This build hook should only run after CI builds. | |
# | |
# There are other cases where we'd want to run something after every build, |
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 Coffee | |
attr_accessor :name | |
attr_accessor :strength | |
def initialize(name, strength) | |
@name = name | |
@strength = strength | |
end | |
def <=>(other_coffee) |
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 'observer' | |
class CoffeeShop | |
include Observable | |
attr_reader :customers | |
def initialize(name, capacity) | |
@name = name | |
@capacity = capacity | |
@customers = [] |
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 'benchmark' | |
# Compare sorting a Hash with an Array | |
arr = [] | |
hash = {} | |
10_000.times.with_index do |i| | |
ascii_code = rand(255) | |
random_char = ascii_code.chr | |
arr << random_char |
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 'fileutils' | |
# __FILE__ keyword in ruby | |
puts "The current ruby file being executed is #{__FILE__}" | |
# Gets the directory name of the file being executed | |
current_directory = File.dirname(__FILE__) | |
puts "The current directory is #{current_directory}" | |
# expands to reveal the pwd (Present working directory) |
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 'logger' | |
class CoffeeShop | |
attr_reader :std_logger, :file_logger | |
def initialize(name) | |
@name = name | |
@menu = [] | |
@std_logger = Logger.new(STDOUT) | |
@file_logger = Logger.new('./coffee_shop.log') |
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
# http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html | |
require 'logger' | |
class CoffeeShop | |
attr_reader :logger | |
def initialize(name) | |
@name = name | |
@menu = [] | |
@logger = Logger.new(STDOUT) |
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
# Restrict arguments to a specified class. | |
require 'optparse' | |
class HelloParser | |
def self.parse(args) | |
options = {} | |
opts = OptionParser.new do |opts| | |
opts.banner = "Usage: name" | |
opts.on('-n', '--name NAME', 'The name of the person to say hello to') do |name| |
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 'uri' | |
require 'open-uri' | |
google_url = "http://google.com/" | |
url = URI.parse(google_url) | |
# Get the hostname | |
puts "The hostname is #{url.hostname}" |
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 test "$#" = 0; then | |
( | |
git diff | |
git ls-files --others --exclude-standard | | |
while read -r i; do git diff -- /dev/null "$i"; done | |
) | |
else | |
git diff "$@" | |
fi |
OlderNewer