barsoom / attr_extras

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

Adding optional attributes #6

Closed bartoszkopinski closed 9 years ago

bartoszkopinski commented 9 years ago

Adding optional attributes:

class Klass
  pattr_initialize :foo, bar: "default value"
end

Klass.new("Foo").send(:bar) # => "default value"
henrik commented 9 years ago

Thanks for this! Nice addition.

Does it work with hash arguments (pattr_initialize [foo, :bar!]) as well? Would be nice to document that since the syntax to use for that isn't obvious. A hash inside the array?

henrik commented 9 years ago

Closing this pull request as it's incomplete. Would be a great thing to have if it covers hash arguments and is fully documented.