Comments (3)
This was discussed multiple times and its not in the scope of this project. You can easily add default values on top in case:
class Person
include Anima.new(:name, :age)
DEFAULTS = { name: '', age: 0 }
def self.new(**attributes)
super(DEFAULTS.merge(attributes))
end
end
Defaults are in fact a form of conditionals and they should be used sparsely. I'll close this issue for now, but please keep trying to convince me with new arguments. I'm known to change my opinion on good ones.
Also in case you wanted you could easily create an anima-defaults
gem adding the functionality, I'd be willing to link to it from the Readme assumig I see some use / maintainership of it.
from anima.
I think it would mostly be because it's kinda easy to make the change. Also, this would allow this project to implement a kind of Null Object pattern, and ease the builder pattern too. That way, creating an "empty, default object" would be simply MyObject.new
, and not
MyObject.new(attr: [], other_attr: "", something_else: SomethingElse.new(other => default, parameters => here))
I think generating a new gem for it would be kinda overkill too...
from anima.
so why not share your domain specific null object this way:
class YourClass
include Anima.new(...)
NULL = new(your_null_params)
end
this is superior to create n null objects. plus points for (deep) freezing it.
from anima.
Related Issues (13)
- You should have a README file HOT 1
- License missing from gemspec HOT 2
- Full key status report on initialization errors HOT 3
- Stack overflow on Ruby 2.1.0 HOT 6
- bug in README HOT 1
- Release v1.0
- Include `Anima::Update` per default. HOT 11
- Add Anima.attribute_names HOT 3
- Optional attributes HOT 5
- Improper documentation for `Anima::InstanceMethods#with`?
- Anima breaks on `#with` and `#to_h` if an attribute is private or protected HOT 1
- Use of mutation testing in anima - Help needed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anima.