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 'erb' | |
require 'benchmark' | |
TEMPLATE = "<b><%= name %></b> in <%= city %>, <%= state_id %>" | |
LOCALS = { :name => 'Wes', :city => 'Seattle', :state_id => 'WA' } | |
def render_with_plain_erb | |
local_variables = Struct.new(*LOCALS.keys).new(*LOCALS.values) | |
ERB.new(TEMPLATE).result(local_variables.instance_eval { binding }) | |
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
ruby-1.8.7-p299 ➜ code ruby webmock_patron_body_stubbing_test.rb | |
Loaded suite webmock_patron_body_stubbing_test | |
Started | |
...F | |
Finished in 0.024057 seconds. | |
1) Failure: | |
test_patron(BodyStubbingTest) [webmock_patron_body_stubbing_test.rb:44]: | |
<"response for foo body"> expected but was | |
<"response for nil body">. |
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 'rubygems' | |
require 'rspec' | |
shared_examples_for :a_foo do |supported_features| | |
it 'responds to #to_s' do | |
subject.should respond_to(:to_s) | |
end | |
it 'responds to #bar' do | |
subject.should respond_to(:bar) |
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-1.8.6-p399 ➜ rvm use 1.8.6 | |
info: Using ruby 1.8.6 p399 | |
ruby-1.8.6-p399 ➜ ruby rspec_constant_spec.rb | |
. | |
Finished in 0.00083 seconds | |
1 example, 0 failures | |
ruby-1.8.6-p399 ➜ rvm use 1.8.7 |
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 'benchmark' | |
n1, n2 = 100, 1000 | |
Benchmark.benchmark do |b| | |
b.report("<<") do | |
hash = Hash.new { |h, k| h[k] = [] } | |
n1.times do |i| | |
n2.times do |i2| | |
hash[i] << i2 | |
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 'parka' | |
# The DSL used in the gemsets block will cause Parka to dynamically generate a bunch of rake tasks: | |
# rake parka:ar_238:install => generates a Gemfile using the ar_238 gemset, and runs `bundle install` against it | |
# rake parka:ar_238:update => runs a `bundle update` against the ar_238 gemset | |
# rake parka:ar_238:update GEM=foo => runs a `bundle update foo` against the ar_238 gemset | |
# rake parka:all:install => generates a Gemfile for all gemsets, and runs `bundle install` against each | |
# | |
# rake parka:ar_238:spec => run the spec task using the current ruby interpreter and the ar_238 gemset | |
# rake parka:ar_235:spec => run the spec task using the current ruby interpreter and the ar_238 gemset |
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
➜ code rvm use 1.8.7 | |
info: Using ruby 1.8.7 p302 | |
ruby-1.8.7-p302 ➜ code rvm gemset create rspec_187_error | |
info: Gemset 'rspec_187_error' created. | |
ruby-1.8.7-p302 ➜ code rvm gemset use rspec_187_error | |
info: Now using gemset 'rspec_187_error' | |
ruby-1.8.7-p302@rspec_187_error ➜ code gem install rspec --pre --no-rdoc --no-ri |
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
>> Routes.user_path(7) | |
=> "/users/7" | |
>> Routes.user_url(7) | |
=> "http://www.some-domain.com/users/7" |
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 private_class_method.rb | |
7 | |
private_class_method.rb:13: private method `bar' called for Foo:Class (NoMethodError) |
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 'benchmark' | |
class MyStruct < Struct.new(:a); end | |
class MyStructHolder | |
def get_via_instance_variable | |
@my_struct ||= MyStruct.new(self) | |
end | |
@@hash = Hash.new do |hash, key| |