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
$ irb | |
>> String.instance_method(:to_s).name | |
=> "to_s" | |
$ irb-1.9 | |
>> String.instance_method(:to_s).name | |
=> :to_s | |
$ jirb | |
>> String.instance_method(:to_s).name |
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
#!/usr/bin/env ruby | |
# Run from toplevel rails checkout to profile a component's requires: | |
# $ ./profile_requires.rb active_support | |
GC.enable_stats | |
require 'rubygems' | |
require 'benchmark' | |
ENV['NO_RELOAD'] ||= '1' | |
ENV['RAILS_ENV'] ||= 'development' |
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
jeremy@foo rails (master) $ ruby -v | |
ruby 1.8.8dev (2009-03-19 revision 23009) [i386-darwin9.6.2] | |
jeremy@foo rails (master) $ ./profile_requires.rb active_support | |
5854.24 KB 222568 obj 139.9 ms active_support | |
171.17 KB 2629 obj 4.1 ms active_support/json | |
23.53 KB 601 obj 0.5 ms active_support/json/decoding | |
136.72 KB 1766 obj 3.3 ms active_support/json/encoding | |
6.49 KB 45 obj 0.2 ms active_support/json/encoders/true_class | |
8.50 KB 88 obj 0.2 ms active_support/json/encoders/time | |
6.47 KB 49 obj 0.2 ms active_support/json/encoders/symbol |
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
jeremy@foo rails (master) $ /usr/local/ruby/1.8.6-ree/bin/ruby -v | |
ruby 1.8.6 (2008-08-08 patchlevel 286) [i686-darwin9.5.0] | |
jeremy@foo rails (master) $ /usr/local/ruby/1.8.6-ree/bin/ruby profile_requires.rb active_support | |
3757.52 KB 110258 obj 87.3 ms active_support | |
104.50 KB 2758 obj 3.3 ms active_support/json | |
16.50 KB 586 obj 0.4 ms active_support/json/decoding | |
78.95 KB 1901 obj 2.7 ms active_support/json/encoding | |
3.26 KB 54 obj 0.1 ms active_support/json/encoders/true_class | |
5.50 KB 97 obj 0.2 ms active_support/json/encoders/time | |
3.21 KB 58 obj 0.2 ms active_support/json/encoders/symbol |
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
# encoding: utf-8 | |
☂ = Class.new { def ☎; puts "⎆" end } | |
☂.new.☎ |
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 AfterTransaction | |
def self.included(base) | |
base.extend(ClassMethods) | |
base.class_eval do | |
class <<self | |
alias_method_chain :transaction, :callbacks | |
end | |
end | |
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
# $/ is the ruby line separator, defaults to \n | |
$/ = '~' | |
File.open('some_file') do |file| | |
file.each_line do |line| | |
# ... | |
end | |
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
# Users: JSON.encode(whatever) | |
# | |
# Implementors: override dump_json(options) returning a Hash, Array, etc | |
# or: override encode_json(encoder) using the encoder API to return a JSON string | |
require 'active_support/core_ext/array/wrap' | |
require 'active_support/core_ext/object/instance_variables' | |
module ActiveSupport | |
module JSON |
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
# Including a module included in a superclass is ignored | |
>> module Foo; end | |
=> nil | |
>> class Numeric; include Foo; end | |
=> Numeric | |
>> Float.ancestors | |
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel] | |
>> class Float; include Foo; end | |
=> Float | |
>> Float.ancestors |
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
# Round expiry to encourage HTTP caching. | |
# 5-minute expiry at 6:03 would round up from 6:08 to 6:10. | |
module QuantizedExpiry | |
def url_for(name, options = {}) | |
unless options[:expires] | |
t = (options.delete(:expires_in) || 5.minutes).to_i | |
options[:expires] = t * (2 + (Time.now.to_i / t)) | |
end | |
super | |
end |