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 run_filters(&blk) | |
m = Module.new do | |
extend self | |
@__filter_endpoint = blk | |
end | |
code = '@__filter_endpoint.call' | |
filter_methods = private_methods.grep(/^filter_/) | |
filter_methods.each do |meth| | |
m.send(:define_method, "__filter_#{meth}", method(meth)) | |
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
class A | |
def f() 'A#f' end | |
end | |
module M | |
def f() 'M#f' end | |
def g() 'M#g' end | |
def k() 'M#k' 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
jobs_per_process = 100 | |
process_count = 10 | |
User.find_in_batches(:batch_size => jobs_per_process * process_count, :conditions => "name like '%00'") do |group| | |
batches = group.in_groups(process_count) | |
batches.each do |batch| | |
Process.fork do | |
ActiveRecord::Base.establish_connection | |
batch.reject { |user| user.nil? }. | |
each {|user| puts user.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
class A | |
class << self | |
def add(ele) | |
@array ||= [] | |
@array << ele | |
end | |
def array | |
@array ||= [] | |
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
def Object.superclasses | |
superclasses = superclass.superclasses if superclass.respond_to?(:superclasses) | |
superclasses ||= [] | |
superclasses.unshift self | |
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
require 'tsort' | |
require 'pp' | |
Node = Struct.new :value, :before, :after | |
class Collection < Array | |
include TSort | |
alias :tsort_each_node :each | |
def tsort_each_child(current, &block) |
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
require 'v8' | |
v8 = V8::Context.new | |
r = v8.eval 'a = {"b": 310399688698392577}' | |
r[b].to_i # => 310399688698392576 (expected: 310399688698392577) |
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 write_cookie?(cookie) | |
@secure || !cookie[:secure] || defined?(Rails.env) && Rails.env.development? | |
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
Rails::Engine < Rails::Railtie | |
Rails::Plugin < Rails::Engine | |
Rails::Application < Rails::Engine | |
I18n::Railtie < Rails::Railtie | |
ActiveSupport::Railtie < Rails::Railtie | |
ActionDispatch::Railtie < Rails::Railtie | |
ActionView::Railtie < Rails::Railtie | |
ActionController::Railtie < Rails::Railtie | |
ActiveRecord::Railtie < Rails::Railtie | |
ActionMailer::Railtie < Rails::Railtie |
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 Object.const_missing(const_name, *args) | |
puts "const_missing #{const_name.inspect}" | |
require './test_class' | |
Object.const_get const_name | |
end | |
obj = TestClass.new | |
puts obj.f # => hello world |