GithubHelp home page GithubHelp logo

Comments (3)

mbj avatar mbj commented on June 3, 2024

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.

mauricioszabo avatar mauricioszabo commented on June 3, 2024

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.

mbj avatar mbj commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.