Permalink
Browse files

Adds an example of a 'private attribute' to the README

  • Loading branch information...
1 parent 51b0e85 commit 3bab6df369cfbcef30058db3b918305e60a361d6 @krisleech krisleech committed Mar 7, 2013
Showing with 22 additions and 0 deletions.
  1. +22 −0 README.md
View
@@ -402,6 +402,28 @@ user = User.new(:scream => 'hello world!')
user.scream # => "HELLO WORLD!"
```
+### Private Attributes
+
+``` ruby
+class User
+ include Virtus
+
+ attribute :unique_id, String, :writer => :private
+
+ def set_unique_id(id)
+ self.unique_id = id
+ end
+end
+
+user = User.new(:unique_id => '1234-1234')
+user.unique_id # => nil
+
+user.unique_id = '1234-1234' # => NoMethodError: private method `unique_id='
+
+user.set_unique_id('1234-1234')
+user.unique_id # => '1234-1234'
+```
+
Credits
-------

0 comments on commit 3bab6df

Please sign in to comment.