You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,19 @@ class User < ApplicationRecord
68
68
end
69
69
```
70
70
71
+
Customize the null class name:
72
+
73
+
```ruby
74
+
classUser < ApplicationRecord
75
+
Null(class_name:"Guest")
76
+
class << self
77
+
alias_method:null, :guest
78
+
end
79
+
end
80
+
81
+
User.guest # returns a User::Guest instance
82
+
```
83
+
71
84
### Void Objects
72
85
73
86
While `Null` objects are singletons (one instance per model), `Void` objects are instantiable null objects that allow creating multiple instances with different attribute values.
@@ -115,6 +128,18 @@ Void objects support the same features as Null objects:
115
128
- Custom methods via block syntax
116
129
- Association handling
117
130
- All ActiveRecord query methods (`null?`, `persisted?`, etc.)
131
+
- Custom class names via `class_name:` parameter
132
+
133
+
```ruby
134
+
classProduct < ApplicationRecord
135
+
Void(class_name:"Placeholder")
136
+
class << self
137
+
alias_method:void, :placeholder
138
+
end
139
+
end
140
+
141
+
Product.placeholder # returns a Product::Placeholder instance
142
+
```
118
143
119
144
Use `Null` when you need a single shared null object instance. Use `Void` when you need multiple null object instances with different attribute values.
0 commit comments