Skip to content
Browse files

Call init on every value that responds to it, even if no args are given.

  • Loading branch information...
1 parent 130416f commit 286ddd3a466c0af20953f84c61ccc83682502b96 @duelinmarkers duelinmarkers committed Sep 1, 2009
Showing with 10 additions and 5 deletions.
  1. +1 −1 lib/renum/enumerated_value_type_factory.rb
  2. +9 −4 spec/renum_spec.rb
2 lib/renum/enumerated_value_type_factory.rb
@@ -22,7 +22,7 @@ def create_values klass, values, &block
value =
klass.const_set(value_name, value)
value.instance_eval &instance_block if instance_block
- value.init *init_args if init_args.any?
+ value.init *init_args if value.respond_to? :init
13 spec/renum_spec.rb
@@ -65,11 +65,12 @@ def abbr
Small("Really really tiny")
Medium("Sort of in the middle")
Large("Quite big")
+ Unknown()
attr_reader :description
- def init description
- @description = description
+ def init description = nil
+ @description = description || "NO DESCRIPTION GIVEN"
@@ -80,12 +81,12 @@ def init description
describe "enum with no values array and values declared in the block" do
- it "provides an alternative means of declaring values where extra information can be provided for initialization" do
+ it "provides another way to declare values where an init method can take extra params" do
Size::Small.description.should == "Really really tiny"
it "works the same as the basic form with respect to ordering" do
- Size.values.should == [Size::Small, Size::Medium, Size::Large]
+ Size.values.should == [Size::Small, Size::Medium, Size::Large, Size::Unknown]
it "responds as expected to arbitrary method calls, in spite of using method_missing for value definition" do
@@ -95,6 +96,10 @@ def init description
it "supports there being no extra data and no init() method defined, if you don't need them" do == "BLONDE"
+ it "calls the init method even if no arguments are provided" do
+ Size::Unknown.description.should == "NO DESCRIPTION GIVEN"
+ end
enum :Rating do

0 comments on commit 286ddd3

Please sign in to comment.
Something went wrong with that request. Please try again.