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
# for Ruby 1.9.2 compatibility | |
gem 'ruby-debug-base19', "0.11.24" | |
gem 'ruby-debug19', "0.11.6" |
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.antialias_method(new_name, old_name) | |
define_method(new_name) { !send(old_name) } | |
end | |
end | |
require 'test/unit' | |
class AntialiasTest < Test::Unit::TestCase | |
class Person |
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
Objector = lambda do |properties| | |
lambda do |meth| | |
properties[meth] | |
end | |
end | |
def Objector.new(props); self[props] 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
#closures as I currently understand them | |
free_variable = 1 | |
clos = lambda { p "I'm a closure because I hold on to #{free_variable += 1}" } | |
non_clos = lambda { |x| p "I'm not a closure :(, because #{x += 1} hasn't changed" } | |
p clos.call | |
p clos.call |
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 Hash | |
def map_keys(&blk) | |
Hash[keys.map(&blk).zip(values)] | |
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
require 'sinatra' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'haml' | |
require 'sequel' | |
require 'sqlite3' | |
get '/' do | |
redirect '/update' unless bookmarks_table_exists? | |
haml :index, :locals => { bookmarks: bookmarks_table } |
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 try_chain *meths | |
meths.inject(self) do |res, meth| | |
break unless result = res.try(meth) | |
result | |
end | |
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 BlankSlate | |
instance_methods.each { |m| undef_method m unless m =~ /^__/ } | |
end | |
class MaybeProxy < BlankSlate | |
attr_reader :obj | |
def initialize(obj) | |
@obj = obj | |
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
# pulled out of a project authored by tpope && rbxbx | |
# not generic enough for general use, but a decent example of | |
# an application specific restful crud abstraction | |
module Incrudable | |
extend ActiveSupport::Concern | |
included do | |
expose(controller_name) { controller_name.classify.constantize.scoped } | |
expose(controller_name.singularize) |
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
Feature: Get | |
In order to interact with the command line | |
As an end user | |
I want to see and enter things | |
Scenario: | |
Given I will see "Private?" | |
Then I will enter "Yes, sir?" | |
Then I will see "Jump" |