MooseX is a postmodern object DSL for Ruby
This is a DSL for object creation, aspects, method delegation and much more. It is based on Perl Moose and Moo, two important modules who add a better way of Object Orientation development (and I enjoy A LOT). Using a declarative stype, using Moose/Moo you can create attributes, methods, the entire constructor and much more. But I can’t find something similar in Ruby world, so I decide port a small subset of Moose to create a powerfull DSL for object construction.
Of course, there is few similar projects in ruby like
But the objetive of MooseX is different: this is a toolbox to create Classes based on DSL, with unique features like
- method delegation ( see ‘handles’)
- lazy attributes
- roles
- parameterized roles
- composable type check
- events
and much more.
This rubygem is based on this modules:
See also:
Why MooseX? Because the namespace MooseX/MooX is open to third-party projects/plugins/extensions. You can upgrade your Moo(se) class using other components if you want. And there is one gem called ‘moose’ :/
THIS MODULE IS EXPERIMENTAL YET! BE CAREFUL!
Talk is cheap. Show me the code!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Installation
Add this line to your application’s Gemfile:
gem 'moosex'
And then execute:
$ bundle
Or install it yourself as:
$ gem install moosex
You need ruby 2.0.x or superior.
Description
MooseX is an extension of Ruby object system. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world.
Read more about Moose on http://moose.iinteractive.com/en/
Motivation
It is fun
Usage
You just need include the MooseX module in your class and start to describe the attributes with our DSL. This module will inject one smart constructor, acessor and other necessary methods.
Instead the normal way of add accessors, constructor, validation, etc
1 2 3 4 5 6 7 8 9 10 11 12 |
|
you can do this:
1 2 3 4 5 6 7 8 9 |
|
Contributing
- Fork it ( http://github.com/peczenyj/MooseX/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request Push to the branch (
git push origin my-new-feature
)