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
#!/bin/sh | |
rvm_current=`rvm current` | |
echo "Installing ruby-debug with $rvm_current ..." | |
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem | |
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem | |
gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem ruby-debug19 -- --with-ruby-include=$rvm_path/src/$rvm_current |
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
ActiveRecord::Base.subclasses. | |
map {|model| model.reflections.values.select {|association| [:has_many, :has_one].include? association.macro }}.flatten. | |
each {|association| association.options[:dependent] = :destroy } |
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
# heredocs are quite flexible | |
without_initial_indentation = <<-END.gsub(/^ {4}/, '') | |
foo | |
bar | |
foo | |
bar | |
END | |
# another example |
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
# Get backtrace for each thread | |
# ruby 1.9 | |
Thread.list.map(&:backtrace) | |
# ruby enterprise edition | |
# http://www.rubyenterpriseedition.com/documentation.html#_obtaining_the_backtrace_of_all_threads | |
require 'thread' | |
caller_for_all_threads |
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
# call methods like constants | |
module Foo | |
def self.bar | |
'tadam' | |
end | |
end | |
Foo::bar # => tadam |
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
# power of extend | |
# can be used to add methods only to top-level object | |
module Rake | |
def task | |
:executed | |
end | |
end | |
extend Rake |
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
# "python-like" import | |
load path, true # => will load new constants and methods under anonymous module | |
Module.nesting.first # => inside loaded file will return the current namespace | |
### | |
module PythonImport | |
def import(path) | |
load 'importer.rb', true |
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
# magic double assignment | |
a = [[a,1]] # => [[[[nil, 1]], 1]] |
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
# fun with constant resolution | |
class Magic | |
def self.const_missing(const) | |
'for children' | |
end | |
end | |
p Magic::Bunny # => for children |
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
# Module.constants allows you to check all available at point of call constants | |
module Bar | |
AvailableUnderNamespace = :constant | |
end | |
class Foo | |
include Bar | |
p Module.constants.include?(:AvailableUnderNamespace) # => true | |
end |