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 counter(start,increment) | |
start -= increment | |
lambda do | |
start += increment | |
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 Configuration | |
attr_accessor :tail_logs, :max_connections, :admin_password, :app_server_config, :port | |
def app_server | |
if block_given? | |
@app_server_config = Configuration.new | |
yield @app_server_config | |
else | |
@app_server_config || Configuration.new | |
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 Configuration | |
attr_accessor :tail_logs, :max_connections, :admin_password, :app_server_config, :port | |
def configurer | |
if block_given? | |
@app_server_config = Configuration.new | |
yield @app_server_config | |
@app_server_config | |
else | |
@app_server_config || Configuration.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
class Object | |
def new(klass, *args) | |
klass.new(*args) | |
end | |
end | |
x = new String | |
p x | |
p new Array |
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
Ruby is awesome!: | |
if Date.today.wednesday? | |
else | |
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 AccessorWrapper | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
def self.sneaky_logger(klass, accessor) | |
@logged_stuff ||= {} | |
@logged_stuff[klass] ||= [] | |
@logged_stuff[klass] << accessor |
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 Object | |
def self.xtend(klass) | |
self.class.send(:include, klass) | |
end | |
end | |
module AccessorWrapper | |
def self.included(base) | |
#base.extend ClassMethods |
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.open('hello.rb', 'wb') {|f| f.write 'class Hello; end' } | |
x = Module.new | |
file = File.open('hello.rb') {|f| f.read } | |
x.module_eval(file) | |
x::Hello | |
#Patch Module: | |
class Module | |
public | |
def load_from_file(file) |
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
#!/usr/bin/env ruby | |
require 'bundler' | |
require 'bundler/runtime' | |
puts 'Building gems.tags from bundle' | |
outpath = 'gems.tags' | |
begin | |
runtime = ::Bundler::Runtime.new Dir.pwd, ::Bundler.definition | |
paths = runtime.specs.map(&:full_gem_path).join(' ').strip |
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
#Took me ages to work this out: | |
def setup_session(session = {}) | |
Rack::Session::Abstract::SessionHash.stub(:new).and_return(session) | |
end | |
#then in your tests | |
before :each do | |
setup_session :user_id => User.first.id | |
get '/user_required' |
OlderNewer