Closed qd3v closed 9 years ago
We're interested in this too and would be happy to help implement. @solnic - what are your thoughts on this?
Can you show me some use cases for that feature? I want to reduce functionality of Virtus in its 2.0 version so in general I'm skeptical when it comes to adding new features.
Our use-case is pretty basic. In some contexts, it's just nicer/prettier to initialize an object using a block-style syntax, instead of a hash.
e.g. instead of this:
AwesomeObject.new(:name => 'John Doe',
:age => 25,
:bio => 'Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.',
:interests => 'Nulla vitae elit libero, a pharetra augue.',
:education => 'Aenean lacinia bibendum nulla sed consectetur.')
we'd like to do this:
AwesomeObject.new do |a|
a.name = 'John Doe'
a.age = 25
a.bio = 'Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.'
a.interests = 'Nulla vitae elit libero, a pharetra augue.'
a.education = 'Aenean lacinia bibendum nulla sed consectetur.'
end
then tap
is your friend, sorry but that won't be added.
Fair enough - thanks for the update.
Is there any strategy, why there's no
yield self if block_given?
for #initialize? https://github.com/solnic/virtus/blob/master/lib/virtus/instance_methods.rb#L16-L19I can implement this small nice feature, just need to discuss should I, and where to:
BTW, I know I can use Post.new.tap for that ;)