README.md in moosex-0.0.7 vs README.md in moosex-0.0.8
- old
+ new
@@ -94,10 +94,38 @@
class Target
def method_x; 1024; end # works with simple methods
def method_y(a,b,c); a + b + c; end # or methods with arguments
end
+class Point3D < Point
+
+ has x: { # override original attr!
+ is: :rw,
+ isa: Integer,
+ default: 1,
+ }
+
+ has z: {
+ is: :rw, # read-write (mandatory)
+ isa: Integer, # should be Integer
+ default: 0, # default value is 0 (constant)
+ }
+
+ has color: {
+ is: :rw, # you should specify the reader/writter
+ reader: :what_is_the_color_of_this_point,
+ writter: :set_the_color_of_this_point,
+ default: :red,
+ }
+
+ def clear
+ self.x= 0 # to run with type-check you must
+ self.y= 0 # use the setter instad @x=
+ self.z= 0
+ end
+end
+
# now you have a generic constructor
p1 = Point.new # x and y will be 0
p2 = Point.new( x: 5 ) # y will be 0
p3 = Point.new( x: 5, y: 4)
foo = Foo.new( bar: 123 ) # without bar will raise exception
@@ -221,12 +249,46 @@
}
end
```
and much more
+## Lazy Attributes
+
+```ruby
+class LazyFox
+ include MooseX
+
+ has something: {
+ is: :lazy
+ }
+
+ has other_thing: {
+ is: :rw,
+ lazy: true,
+ predicate: true,
+ clearer: true,
+ builder: :my_build_other_thing,
+ }
+
+ has lazy_attr_who_accepts_lambda: {
+ is: :lazy,
+ builder: lambda{ |object| object.something }
+ }
+
+ def build_something
+ 1024
+ end
+
+ private
+ def my_build_other_thing
+ 128
+ end
+end
+```
+
## TODO
-1. Support to lazy attributes
+1. Support to lazy attributes [done]
2. Support to BUILD and BUILDARGS hook
3. Support to Roles ( it is a Module on Steroids )
4. Support to after/before/around
5. Improve the typecheck system (we should specify: we need an array of positive integers)
6. Improve the exception and warning system