From: Trans Date: 2006-10-29T18:30:10+09:00 Subject: Re: Interesting trival example of why open classes are good? 'ello -- Peter Michaux wrote: > Do you know of a nice little example that doesn't modify a built in > Ruby class? I didn't realize I wasn't specific enough in my request. # --- dynamic/X/here.rb class X def here puts "Here I am!" end end # --- class X def method_missing(s, *a, &b) begin require 'dynamic/X/#{s}' send(s, *a, &b) rescue LoadError super end end end X.new.here #=> "Here I am!" It's interesting pattern, don't you think? If you have large chunks of code that only get used once in a while it's a way to speed up initial load times. Actually you could write an entire program this way --with each method in a different file (but that can be a chore to maintain). In anycase it's an example of what you can do with open classes. T.