This file contains hidden or 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
" :Gist | |
" post whole text to gist. | |
" | |
" :'<,'>Gist | |
" post selected text to gist. | |
" | |
" :Gist -p | |
" post whole text to gist with private. | |
" | |
" :Gist XXXXX |
This file contains hidden or 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
i = 0 | |
10.times do |i| | |
i += 1 | |
end | |
puts i | |
% ruby block_scope.rb | |
10 | |
% ruby19 block_scope.rb |
This file contains hidden or 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
--- a/actionpack/lib/action_controller/routing/route_set.rb | |
+++ b/actionpack/lib/action_controller/routing/route_set.rb | |
@@ -436,7 +436,7 @@ module ActionController | |
def recognize(request) | |
params = recognize_path(request.path, extract_request_environment(request)) | |
request.path_parameters = params.with_indifferent_access | |
- "#{params[:controller].camelize}Controller".constantize | |
+ "#{params[:controller].to_s.camelize}Controller".constantize | |
end |
This file contains hidden or 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
From dea2c88948364c5f6e6f853ff8cdd0fcd68158d0 Mon Sep 17 00:00:00 2001 | |
From: Akira Matsuda <[email protected]> | |
Date: Thu, 9 Jul 2009 16:08:59 +0900 | |
Subject: [PATCH] Fix validation on associations to process I18n aware error messages | |
--- | |
.../lib/active_record/autosave_association.rb | 4 +- | |
activerecord/lib/active_record/validations.rb | 24 ++++- | |
.../test/cases/autosave_association_test.rb | 16 ++-- | |
activerecord/test/cases/validations_i18n_test.rb | 106 ++++++++++++++++++++ |
This file contains hidden or 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
From 871755d7d5653ddcf64fed1f758cbafaa91a3655 Mon Sep 17 00:00:00 2001 | |
From: Akira Matsuda <[email protected]> | |
Date: Sun, 19 Jul 2009 14:36:44 +0900 | |
Subject: [PATCH] Ruby 1.9.2 compat: name method was renamed to __name__ since MiniTest 1.4.x | |
--- | |
activesupport/lib/active_support/test_case.rb | 3 ++- | |
1 files changed, 2 insertions(+), 1 deletions(-) | |
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb |
This file contains hidden or 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
gem 'rspec', :lib => false | |
gem 'rspec-rails', :lib => false | |
generate :rspec | |
generate :rspec_scaffold, 'user', 'name:string' | |
rake 'db:migrate' |
This file contains hidden or 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
function! s:RunRspec (opts) | |
let rails_spec_path_re = '\<spec/\(models\|controllers\|views\|helpers\)/.*_spec\.rb$' | |
if( expand('%') =~ rails_spec_path_re && filereadable('script/spec') ) | |
"let command = '!ruby script/spec ' | |
let spec_command = '!rspec ' | |
if filereadable('tmp/pids/spec_server.pid') | |
let spec_command = spec_command . ' --drb ' | |
endif | |
else |
This file contains hidden or 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 use_factory(name) | |
require 'factory_girl' | |
defined_factories = Factory.factories.try(:map) {|f| f.first} | |
require "spec/factories/#{name}" | |
loaded_factories = Factory.factories.try(:map) {|f| f.first} - defined_factories | |
puts "loaded: #{loaded_factories.join(', ')}" | |
end |
This file contains hidden or 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
products = Product.where("price = 100").limit(5) # No query executed yet | |
products = products.order("created_at DESC") # Adding to the query, still no execution | |
products.each { |product| puts product.price } # That's when the SQL query is actually fired | |
class Product < ActiveRecord::Base | |
scope :pricey, where("price > 100") | |
scope :latest, order("created_at DESC").limit(10) | |
end |
This file contains hidden or 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 RegexpableHash | |
def kakko_with_regexp(key) | |
if val = kakko_without_regexp(key) | |
return val | |
end | |
if matched_key = self.keys.detect {|k| Regexp.new("\\A#{k}\\Z") =~ key.to_s} | |
if (val = kakko_without_regexp(matched_key)).is_a? String | |
# 0が含まれてるけどまぁいっか的な。 | |
Regexp.last_match.to_a.each_with_index do |m, i| | |
val.gsub! "$#{i}", m |
OlderNewer