Module: Tins::BlankSlate
- Defined in:
- lib/tins/dslkit.rb
Class Method Summary collapse
-
.with(*ids) ⇒ Object
Creates an anonymous blank slate class, that only responds to the methods *ids.
Class Method Details
.with(*ids) ⇒ Object
Creates an anonymous blank slate class, that only responds to the methods *ids. ids can be Symbols, Strings, and Regexps that have to match the method name with #===.
284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/tins/dslkit.rb', line 284 def self.with(*ids) opts = Hash === ids.last ? ids.pop : {} ids = ids.map { |id| Regexp === id ? id : id.to_s } klass = opts[:superclass] ? Class.new(opts[:superclass]) : Class.new klass.instance_eval do instance_methods.each do |m| m = m.to_s undef_method m unless m =~ /^(__|object_id)/ or ids.any? { |i| i === m } end end klass end |