Skip to content

Instantly share code, notes, and snippets.

module Blackbox
class Registry
module Query
def registry
@registry ||= Blackbox::Registry.new
end
def configure
yield registry
module ActiveRecord
class KindRollback < Rollback
end
end
module UpdateAttributesWithKind
def self.included(model_class)
model_class.alias_method_chain :update_attributes, :kind
end
@bguthrie
bguthrie / libxml_active_resource.rb
Created January 31, 2009 23:28
A patch for ActiveResource that allows it to use LibXML to parse documents. Use to speed up ARes.
require 'libxml'
module LibXML
module XML
module Conversions
module Document
def to_hash
root.to_hash
end
end
class UsersController < ResourceFull::Base
identified_by :username, :unless => lambda { |id| id =~ /^[0-9]+$/ }
queryable_with :city, :state, :from => :address
queryable_with :name, :columns => [:first_name, :last_name]
queryable_with :email_address, :fuzzy => true
queryable_with :is_active, :scope => :active
orderable_by :city, :from => :address
class String
def to_widget
Widget.new self.gsub(/foo/, "bar")
end
end
irb(main):003:0> "".method(:to_widget)
=> #<Method: String#to_widget>
irb(main):003:0> "".method(:to_widget)
=> #<Method: String#to_widget>
irb(main):003:0> "".method(:to_widget)
=> #<Method: String(StringExtensions)#to_widget>
module BetterToInteger
def self.included(string_class)
string_class.alias_method_chain :to_i, :logging
end
def to_i_with_logging
returning(to_i_without_logging) do |new_value|
logger.log "Converting from #{self} to #{new_value}"
end
end
["Guybrush", "Elaine", "LeChuck"] each(name, "Hello #{name}" println)
["Guybrush", "Elaine", "LeChuck"].each {|name| puts "Hello #{name}"}
*** - couldn't find cell 'name' on 'Origin_0x295106F' (Condition Error NoSuchCell)