lib/surrounded/shortcuts.rb in surrounded-1.0.0 vs lib/surrounded/shortcuts.rb in surrounded-1.1.0

- old
+ new

@@ -1,19 +1,31 @@ module Surrounded module Shortcuts private def define_shortcut(name) - singleton_class.send(:define_method, name) do |*args| - instance = self.new(*args) - instance.public_send(name) + # if keyword initialize + if instance_method(:initialize).parameters.dig(0,0) == :keyreq + singleton_class.send(:define_method, name) do |**args| + instance = begin + self.new(**args) + end + instance.public_send(name) + end + else # non-keyword initialize + singleton_class.send(:define_method, name) do |*args| + instance = begin + self.new(*args) + end + instance.public_send(name) + end end end def store_trigger(*names) names.each do |name| define_shortcut(name) end super end end -end \ No newline at end of file +end