Permalink
Browse files

updating readme

  • Loading branch information...
1 parent 70c48f7 commit 2a63e23711bc2a1debdacbabaad5cf6199a92f80 @beerlington beerlington committed Feb 8, 2013
Showing with 22 additions and 0 deletions.
  1. +10 −0 CHANGELOG.md
  2. +12 −0 README.md
View
@@ -8,6 +8,16 @@
classy_enum_attr :priority, :default => 'medium'
end
+ class Alarm < ActiveRecord::Base
+ classy_enum_attr :priority, :default => lambda {|enum| enum.last
+}
+ end
+
+* Adding ClassyEnum::Base#last. It's not part of the enumerable module
+ but it makes sense in this case.
+
+ Priority.last # => Priority::High
+
## 3.1.3
* Fixes saving and reloading ActiveRecord models that assign enum using
View
@@ -206,6 +206,18 @@ end
Alarm.new.priority # => Priority::Medium
```
+You may also use a Proc object to set the default value. The enum class
+is yielded to the block and can be used to determine the default at
+runtime.
+
+```ruby
+class Alarm < ActiveRecord::Base
+ classy_enum_attr :priority, :default => lambda {|enum| enum.max }
+end
+
+Alarm.new.priority # => Priority::High
+```
+
## Back reference to owning object
In some cases you may want an enum class to reference the owning object

0 comments on commit 2a63e23

Please sign in to comment.