Skip to content

Instantly share code, notes, and snippets.

# require_here.rb
# by Josh Susser
class String
# __FILE__.require_here 'foo' # => require 'CURRENT_DIR/foo'
# __FILE__.require_here %w(lib foo) # joins path segments so you don't have to
# __FILE__.require_here # add the current file's directory to the load path
def require_here(path=nil)
here = File.expand_path(File.dirname(self))
if path
# an object representing a duck type that can be used in a case expression
class Protocol
def initialize(*selectors)
@selectors = selectors
end
def ===(object)
@selectors.all? {|selector| object.respond_to?(selector)}
end
end
### meta magic boolean attributes
def self.attr_boolean(attr_name)
class_eval(<<-CODE, __FILE__, __LINE__)
def #{attr_name}=(#{attr_name})
@#{attr_name} = !!(/^1|true$/i =~ #{attr_name}) # yes, we need a boolean
end
def #{attr_name}
@#{attr_name}
end
<h1>Listing topics</h1>
<table>
<tr>
<th> </th>
<th>Votes</th>
<th>Title</th>
<th>Description</th>
</tr>
# put at top of test_helper.rb
require 'yaml'
Dir[File.expand_path(File.join(File.dirname(__FILE__), "fixtures/**/*.yml"))].each do |f|
begin
YAML.load_file(f)
rescue StandardError => e
puts "!!!!! YAML parse error in file: #{f}"
puts e.message
exit 1
[jruby:1.4.0RC1] potrero:tracker pivotal$ jruby -S gem uninstall twitter
Successfully uninstalled twitter-0.6.14
[jruby:1.4.0RC1] potrero:tracker pivotal$ jruby -S geminstaller
Invoking gem install for mongrel, version 1.1.5.
Invoking gem install for nokogiri, version 1.3.3.
Invoking gem install for twitter, version 0.6.14.
[RubyGems:stderr] ERROR: Error installing twitter:
ERROR: Failed to build gem native extension.
/Users/pivotal/.rvm/jruby-1.4.0RC1/bin/jruby extconf.rb
module Comparable
def min(*values)
(values << self).min
end
def max(*values)
(values << self).max
end
end
nkallen_: nkallen_: anyway, i want to stress that we basically agree about things so i want to be sure that the tone of the blog post is such
[7:25pm] nkallen_: [7:17pm] nkallen_: i would argue that what you do in rails 3 (according to these tweets I've read)
[7:25pm] nkallen_: [7:17pm] nkallen_: is exactly what I propose... this is just how one might do it in Ruby
[7:25pm] nkallen_: [7:18pm] nkallen_: but my point is conceptual and not about ruby
[7:25pm] nkallen_: [7:18pm] nkallen_: it applies to every oo language and also I might argue to functional languages
[7:25pm] nkallen_: [7:18pm] nkallen_: which is to structure a program around the ability to layer on enhanced functionality and ensure that no assumptions are hardcoded by abstracting over the manufacture of objects
[7:25pm] nkallen_: [7:19pm] nkallen_: in the literature, these techniques are called DI, decorators, and factories.
[7:25pm] nkallen_: [7:20pm] nkallen_: i like these terms because they reflect the concepts that are at work. because ruby m
gem list | cut -f 1 -d " " | xargs -E gem gem dep -R $gem | grep -v "^ \w" | grep -P "^[^\s][^\n]+\n[^ ]" -o | grep -v "^$" | sort | cut -f 2 -d " "
@joshsusser
joshsusser / gist:672940
Created November 11, 2010 18:26
always do bundle open using TextMate
alias bo="env EDITOR=mate bundle open $*"