Sha256: 8c8cdd28b2e4382cbb8588619dd6a3e2c6e8577d75c5f899ab9a0cf8a43d3580
Contents?: true
Size: 529 Bytes
Versions: 60
Compression:
Stored size: 529 Bytes
Contents
class Class # Creates a new subclass of self, with a name "under" our own name. # Example: # # x = Foo::Bar.subclass('Zap'){} # x.name # => Foo::Bar::Zap_1 # x.superclass.name # => Foo::Bar def subclass(base_name, &body) klass = Class.new(self) class_name = "#{base_name}_#{class_count!}" instance_eval do const_set(class_name, klass) end klass.instance_eval(&body) klass end private def class_count! @class_count ||= 0 @class_count += 1 @class_count end end
Version data entries
60 entries across 60 versions & 10 rubygems