I see a lot of people using keyword arguments in their Ruby code. I also see a lot of people using options hashes. When should I use keyword arguments and when should I use options hashes? This really confuses me. From what I've seen keyword arguments are much better than options hashes in many cases. For instance:
class Foo
def initialize(kwarg1: nil, kwarg2: nil)
@var1 = kwarg1 if kwarg1
@var2 = kwarg2 if kwarg2
end
end
looks much better and clearer than
class Foo
def initialize(options = {})
@var1 = options[:var1] if options[:var1]
@var2 = options[:var2] if options[:var2]
end
end