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 Usable | |
def config | |
@config ||= Config.new | |
end | |
def use(mod, options = {}) | |
send :include, mod unless self < mod | |
if block_given? | |
yield config | |
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
# Original | |
name, categories = if product.categorie_names.present? | |
prod_categories = product.category_names.split('>') | |
[prod_categories.pop, prod_categories] | |
end | |
# Refactored using coercion and Ruby's pattern matching | |
*categories, name = *product.categorie_names.to_s.split('>') |
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 'benchmark' | |
class ScratchNGo | |
#= Class Description | |
# Looks for a correlation between method call time and # classes in the object space. We do this by creating an initial | |
# sample size of new classes, each defined with the same number of methods. We then benchmark the call time for all methods of the | |
# original sample size of classes. We then create additional sets of class samples, measuring the call time of the original | |
# set each time. | |
def initialize(args) | |
@class_size = (args.pop || 5_000).to_i |
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
# if (me == 'ryan' and you == 'foo') || dude | |
# call_foo you | |
# elsif you == 'bar' | |
# call_bar you | |
# else | |
# puts "don't know who to call" | |
# return 'wut' | |
# end | |
s(:if, |
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
# | |
# AUTOMATICALLY GENERATED SPEC | |
# | |
require "spec_helper" | |
describe UsersController do | |
subject { described_class.new } | |
describe "#index" do |
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
describe DRG::Ruby::Condition do | |
let(:sexp) {} | |
subject { described_class.new sexp } | |
describe "#initialize" do | |
end | |
describe "#short_statement" do | |
context "if @statement =~ /(unless|if)(.+)$/ then" do |
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
# = Description | |
# Loads all words in the dictionary into memory and finds the longest word | |
# | |
# Elixir | |
File.read!("/usr/share/dict/words") |> String.split |> Enum.max_by(&String.length/1) |> IO.puts | |
#=> formaldehydesulphoxylate | |
# Time (after compiled): | |
# real 0m1.887s | |
# user 0m1.722s | |
# sys 0m0.247s |
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
#= Should be able to handle phone numbers with varying lengths | |
# length of 11 | |
format_number('18083334444') #=> '+1 (808) 333-4444' | |
# length of 12 | |
format_number('639173334444') #=> '+63 (917) 333-4444' | |
# length of 13 | |
format_number('6140403334444') #=> '+614 (040) 333-4444' | |
# length of 14 | |
format_number('00447743334444') #=> '+0044 (774) 333-4444' |
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
# config/initializers/quiet_assets.rb | |
class QuietAssets | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
original_level = Rails.logger.level | |
if env['PATH_INFO'] =~ %r{\A/assets/} | |
Rails.logger.level = Logger::WARN |
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
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails', branch: 'master' # master against ref "f1f0a3f8d99aef8aacfa81ceac3880dcac03ca06" |