Metaprogrammazione in Ruby
class Wrapper
attr_accessor :internal
def self.forwards(*methods)
[*methods].each do |method|
class_eval("
def #{method}(*args, &blk)
self.internal.send(#{method.to_sym.inspect}, *args, &blk)
end
")
end
end
forwards :to_i, :length, :split
end
w = Wrapper.new
w.internal = "12 13 14"
puts w.to_i
puts w.length
puts w.split('1')
5 Ottobre 2008
Categorie: Uncategorized
Articoli simili
- Rails 2.1.1: rilasciata nuova versione di Ruby on Rails
- Rails 2.1 e ottimizzazione Active Record
- Panoramica IDE per Ruby e Rails
- Tempo di passare a Ruby 1.9
- Rails 2.2.2 finalmente rilasciato