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
# define | |
class Object | |
def cascade(method_name, *args, &block) | |
self.send(method_name, *args, &block) | |
self | |
end | |
# catch the cascade | |
def method_missing(method_name, *args, &block) | |
sig = /^__/ |
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 Enuma | |
def enumerated(type_name, *members, &block) | |
@enums = [] | |
type_class = const_set(type_name, Enuma::Type.new(*members)) | |
instance_eval(&block) | |
finalize(@enums, type_class) | |
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 A | |
def initialize | |
@lambda = ->(x) { puts "lambda: #{x}" } | |
@proc = Proc.new { |x| puts "proc: #{x}" } | |
@method = method(:_method) | |
end | |
def lambda(x) | |
@lambda[x] | |
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 SampleContracts | |
BASE_PATH = "downloads/sample_contracts/" | |
Contract = Struct.new(:type, :name, :title) do | |
# Struct responds to .call so it can be used for Enumerable.find(ifnone) | |
def self.call | |
new | |
end | |
# By adding this method we get a struct that plays nicely with destructuring |
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 Configuration | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
end | |
class ModuleBuilder |
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
# Example of prototyping models with a mix of ActiveRecord and Virtus | |
# | |
# Useful with large models where some fields are in flux during spiking/dev | |
# and you don't want or need to run migrations to try ideas out. | |
class A < ActiveRecord::Base | |
# ... | |
# belongs_to | |
# has_many |
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 "active_support/all" | |
class Event | |
STATES = %w(active archived) | |
def self.types(&block) | |
return to_enum(__callee__) unless block | |
types = { |
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 'thread' | |
q = Queue.new | |
(0..1000).each{ |i| q << i } | |
puts q.length | |
Thread.new do | |
sleep 1 | |
puts "FIRST #{q.pop}" | |
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
# $: << File.expand_path("../../recipes", __FILE__) | |
# Don't worry about the load path man, Capistrano's got your back! | |
module Capistrano | |
if const_defined? :Configuration | |
Configuration.instance(true).load do | |
@load_paths << File.expand_path("../recipes", __FILE__) | |
load "log" | |
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
# encoding: utf-8 | |
class DocumentUploader < CarrierWave::Uploader::Base | |
include ::CarrierWave::Backgrounder::Delay | |
include CarrierWave::MimeTypes | |
# Include RMagick or MiniMagick support: | |
include CarrierWave::RMagick | |
# include CarrierWave::MiniMagick | |
include CarrierWave::UNOConv |