Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix default values example

  • Loading branch information...
commit 51e420bafbb611ff2419dff5078ccb89e9338c5e 1 parent ef31ea2
@fgrehm fgrehm authored
Showing with 11 additions and 7 deletions.
  1. +11 −7 README.md
View
18 README.md
@@ -61,13 +61,16 @@ class Page
include Virtus
attribute :title, String
-
+
# default from a singleton value (integer in this case)
attribute :views, Integer, :default => 0
-
+
+ # default from a singleton value (boolean in this case)
+ attribute :published, Boolean, :default => false
+
# default from a callable object (proc in this case)
attribute :slug, String, :default => lambda { |page, attribute| page.title.downcase.gsub(' ', '-') }
-
+
# default from a method name as symbol
attribute :editor_title, String, :default => :default_editor_title
@@ -76,10 +79,11 @@ class Page
end
end
-page = Page.new(:title => 'Virtus Is Awesome', :editor_title => 'Virtus README')
-page.slug # => 'virtus-is-awesome'
-page.views # => 0
-page.editor_title # => "UNPUBSLISHED: Virtus README"
+page = Page.new(:title => 'Virtus README')
+page.slug # => 'virtus-readme'
+page.views # => 0
+page.published # => false
+page.editor_title # => "UNPUBLISHED: Virtus README"
```
**Embedded Value**
Please sign in to comment.
Something went wrong with that request. Please try again.