barsoom / attr_extras

Takes some boilerplate out of Ruby with methods like attr_initialize.
MIT License
560 stars 31 forks source link

pattr_initialize method doesn't support the keyword arguments notation correctly #28

Closed roman-dubrovsky closed 5 years ago

roman-dubrovsky commented 5 years ago

Hello 👋

thank you for creating this library. I really enjoy to use it.

I've faced with the bug that pattr_initialize (as well as vattr_initialize and rattr_initialize methods) doesn't support default values for keyword arguments which were described in the attr_initialize notation for keyword arguments. I can check it in the Rails console

> class Test
>   pattr_initialize [value: true]
> end
NameError: invalid attribute name `{:value=>true}'
...

BTW, when I'm using attr_initialize and att_private separately, it works correctly

> class Test
>   attr_initialize [value: true]
>   attr_private :value
>
*   def  test
>     value.to_s
>   end
> end
=> :test
> Test.new.test
=> "true"
> Test.new(value: 1).test
=> "1"
roman-dubrovsky commented 5 years ago

Fixed. Check https://github.com/barsoom/attr_extras/pull/29