Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
# In irb, can type: # people/6 instead of Person.find(6) # That is, can paste in urls into irb to find objects. class ModelProxy def initialize(klass) @klass = klass end def /(id) @klass.find(id) end end def define_model_find_shortcuts model_files = Dir.glob("app/models/**/*.rb") model_names = model_files.map { |f| File.basename(f).split('.')[0..-2].join } model_names.each do |model_name| Object.instance_eval do define_method(model_name.pluralize) do |*args| ModelProxy.new(model_name.camelize.constantize) end end end end
From the Design Piracy series on my blog: