Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize param can't work with &:symbol notation #13

Open
loadkpi opened this issue Dec 21, 2021 · 1 comment
Open

Finalize param can't work with &:symbol notation #13

loadkpi opened this issue Dec 21, 2021 · 1 comment

Comments

@loadkpi
Copy link

loadkpi commented Dec 21, 2021

Is it by design?

> Proc.new{|obj|obj.x}.arity
=> 1
> Proc.new(&:x).arity
=> -2
> class A < SmartCore::Operation; param :text, finalize: Proc.new{|obj|obj.x}; end
=> nil
> class A < SmartCore::Operation; param :text, finalize: proc(&:x); end
/home/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/smart_initializer-0.9.0/lib/smart_core/initializer/attribute/factory/base.rb:95:in `prepare_finalize_param': Lambda-based finalizer should have arity equal to 1 or equal to -1 (your lambda object should require one attribute) (SmartCore::Initializer::ArgumentError)
@0exp
Copy link
Member

0exp commented Jan 10, 2022

Yes, finalize has a lambda-based behavior nature. It is necessary to support only the one parameter (and you must define it) in order to have an ability to validate your constructor: it should be consistent and correctly invokable.

But your case provides an object that should be worked fine cuz it is intuitively correct 🤔 I will check out this approach deeply 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants