Skip to content

Instantly share code, notes, and snippets.

def gimme_class
eval %{
class MethodClass
def where_am_i?
puts "in method!"
end
end
}
obj = MethodClass.new
def gimme_class
method_class = Class.new do
def where_am_i?
puts "in method!"
end
end
obj = method_class.new
obj.where_am_i?
end
def gimme_class
class MethodClass
def where_am_i?
puts "in method!"
end
end
obj = MethodClass.new
obj.where_am_i?
end
@ptzn
ptzn / american_date_monkey_patch.rb
Created January 14, 2011 16:47
Use american date format as default in Ruby 1.9
# Date.parse() with Ruby 1.9 is now defaulting to the European date style where the format is DD/MM/YYYY, not MM/DD/YYYY
# patch it to use US format by default
if RUBY_VERSION >= '1.9'
class String
def to_date
if self.blank?
nil
elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
::Date.civil($3.to_i, $1.to_i, $2.to_i)
else
@ptzn
ptzn / gist:779852
Created January 14, 2011 16:44
IRB session with date format difference in ruby 1.9 & 1.8
# ruby 1.9.2
> Date._parse("11/15/2010", false).values_at(:year, :mon, :mday)
=> [2010, 15, 11]
# ruby 1.8
> Date._parse("11/15/2010", false).values_at(:year, :mon, :mday)
=> [2010, 11, 15]
@ptzn
ptzn / gist:777802
Created January 13, 2011 12:37
autotest-growl configuration
require 'autotest/growl'
Autotest::Growl::clear_terminal = false
@ptzn
ptzn / gist:777800
Created January 13, 2011 12:35
install autotest-growl
$ rvm use ree@global
$ gem install ZenTest autotest-rails autotest-growl
server {
listen 80;
server_name SERVER_NAME;
root PATH_TO_PUBLIC;
passenger_enabled on;
# serve static files directly
location ~ .html {
root PATH_TO_PUBLIC;
}
@ptzn
ptzn / gist:712897
Created November 24, 2010 01:04
Using %SerialObject types
# %SerialObject types saved as string represents all object properties separated by commas,
# for example HM.TimeStampClass may look like "2004-04-16 03:20:07,BOB,2010-06-04 05:25:04,NJM,,117604"
# 1. Create a TimeStamp class that wrap %SerialObject
# Note the importance of the attributes declaration order, they will be mapped to string in this order
# Also you can override default mapping order via mapping method:
# def mapping
# [:attribute2, :attribute1, ...]
# end
class TimeStamp < Intersys::Serial::Object
server {
listen 80 default;
server_name _;
set $domain $host;
if ($domain ~ "^(w{3}\.)?(.*?)\.com") {
set $domain $2;
}
location / {