-
Notifications
You must be signed in to change notification settings - Fork 99
TIP: Autoload CORE
trans edited this page Aug 23, 2010
·
5 revisions
Want to see a cool trick? How about loading CORE methods automagically. It’s like Ruby’s #autoload for core extensions.
require 'facets/opesc' class Object # This will automatically load (most) core methods # if they are not present when called. def method_missing(methodname, *a, &b) methodname = OpEsc.escape(methodname) begin require "facets/#{class}/#{methodname}" __send__(methodname, *a, &b) rescue LoadError super end end end
NOTE: In version 2.8.x and less, this was possible simply via:
require 'facets-live'
As of version 3.0+ this has been deprecated for being a YAGNI. Which accounts for this “tip” if you still would like to do it.
I moved the code into lib/more/facets/auto_core.rb
, if you really want a quick way to do this.
require 'facets/auto_core'
Now that’s just some craziness, isn’t it ;-)