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 | |
irb(main):001:0> self.instance_eval "def method_missing(sym); sym.to_s; end" | |
=> nil | |
irb(main):002:0> String.class_eval 'def method_missing(sym); "#{self} #{sym.to_s}"; end' | |
=> nil | |
irb(main):003:0> i.love.cookies! | |
=> "i love cookies!" | |
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
# bloopsaphone won my heart | |
require '../bloopsaphone/ext/ruby/bloops' | |
# the song object | |
b = Bloops.new | |
b.tempo = 320 | |
saw = b.sound Bloops::SAWTOOTH | |
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 TheExtended | |
def using_the_thing | |
"I use #{a_thing}!" | |
end | |
def a_thing | |
raise "O NOSE!" | |
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
def merge_ad_data! | |
return unless adv_fields = @values.delete('AdvFields') | |
adv_fields = Zlib::GzipReader.new( | |
StringIO.new(Base64.decode64( adv_fields))).read | |
adv_fields = JSON.parse(adv_fields).map { |af| JSON.parse(af) } |
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
if ENV['DATABASE_URL'] | |
::DB = Sequel.sqlite(ENV['DATABASE_URL']) | |
else | |
dbfile = File.dirname(__FILE__) + "/db/#{env}.sqlite3" | |
FileUtils.touch(dbfile) | |
::DB = Sequel.sqlite(dbfile) | |
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 add_rpc_method_with_soapaction_as(name, name_as, soapaction, *params) | |
param_def = SOAPMethod.create_rpc_param_def(params) | |
qname = XSD::QName.new(@namespace, name_as) | |
@proxy.add_rpc_method(qname, soapaction, name, param_def) | |
add_rpc_method_interface(name, param_def) | |
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 MemoryProfiler | |
# profile is a CLEAN, totally minimal memory profiler: | |
# | |
# * 1 thread | |
# * 2 hashes (curr, prev) | |
# * classes as keys | |
# * fixnums as values. | |
# | |
# No extra memory required if I can help it. Keep it as simple as |
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
-# the require for fastthread is run together on one line to avoid unimportant coverage analysis skip | |
-# | |
-begin; require 'fastthread'; rescue LoadError; puts "FastThread not installed - using default thread/mutex ha | |
+ | |
+begin | |
+ require 'fastthread' | |
+rescue LoadError | |
+ puts "FastThread not installed - using default thread/mutex hanlding" | |
+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 'rubygems' | |
require 'test/unit' | |
require 'mocha' | |
class Foo | |
def self.foo(a_param) | |
a_param.upcase | |
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
module Kernel | |
def omg_mem! | |
puts "From #{caller[0]}" | |
puts `ps vx | grep mongrel`.split(' ')[7] | |
end | |
end |
OlderNewer