Permalink
Browse files

Refactor creation into factory

git-svn-id: http://renum.rubyforge.org/svn/trunk@7 0cae1b2a-91f7-40ab-9a3c-fdb74ccff792
  • Loading branch information...
1 parent f0edcf0 commit da87c3c178316d4e28206110d1afe3c6887bcd21 duelin_markers committed Nov 2, 2007
Showing with 16 additions and 7 deletions.
  1. +2 −7 lib/renum.rb
  2. +14 −0 lib/renum/enumerated_value_type_factory.rb
View
@@ -1,14 +1,9 @@
$:.unshift File.dirname(__FILE__)
-require 'renum/enumerated_value'
+require 'renum/enumerated_value_type_factory'
module Renum
def enum type_name, values, &block
- klass = Class.new EnumeratedValue
- Object.const_set(type_name, klass)
- klass.class_eval &block if block_given?
- values.each do |name|
- klass.const_set(name, klass.new(name))
- end
+ EnumeratedValueTypeFactory.create(type_name, values, &block)
end
end
@@ -0,0 +1,14 @@
+require 'renum/enumerated_value'
+module Renum
+ module EnumeratedValueTypeFactory
+ def create type_name, values, &block
+ klass = Class.new EnumeratedValue
+ Object.const_set(type_name, klass)
+ klass.class_eval &block if block_given?
+ values.each do |name|
+ klass.const_set(name, klass.new(name))
+ end
+ end
+ module_function :create
+ end
+end

0 comments on commit da87c3c

Please sign in to comment.