Is there a built-in method in Ruby that requires keyword arguments?

I know that in Ruby 2.0 and later you can have keyword arguments, so you can define a method like this:

def foo(inline_argument, *args, **kwargs, &block)
  puts 'bar'
end

However, I was wondering: is there a built-in method that uses keyword arguments?

+4
source share
1 answer

I cded into my Ruby installation directory and ran grep -r ', \*\*' .and found that yes, there are methods in stdlib that use **kwargs, but only in the library open3.rb.

./lib/ruby/2.1.0/open3.rb:  def popen3(*cmd, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def popen2(*cmd, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def popen2e(*cmd, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def capture3(*cmd, stdin_data: '', binmode: false, **opts)
./lib/ruby/2.1.0/open3.rb:  def capture2(*cmd, stdin_data: '', binmode: false, **opts)
./lib/ruby/2.1.0/open3.rb:  def capture2e(*cmd, stdin_data: '', binmode: false, **opts)
./lib/ruby/2.1.0/open3.rb:  def pipeline_rw(*cmds, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def pipeline_r(*cmds, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def pipeline_w(*cmds, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def pipeline_start(*cmds, **opts, &block)
./lib/ruby/2.1.0/open3.rb:  def pipeline(*cmds, **opts)

EDIT

@mdesantis rb_get_kwargs; , C-, args.

Dir.new( string, encoding: enc ) -> aDir

Array#sample(n, random: rng) -> new_ary
Array#shuffle!(random: rng) -> ary

GC.start(full_mark: false) -> nil
+3

All Articles