What is the behavior when using both positional and keyword arguments in Ruby?

The order is as follows: required arguments arguments with default values (arg=default_value notation) optional arguments (*args notation, sometimes called “splat parameter”) required arguments, again keyword arguments optional (arg:default_value notation, since 2.0.0) intermixed with required (arg: notation, since 2.1.0) arbitrary keyword arguments (**args notation, since 2.0.0) block argument (&blk notation) For example: def test(a, b=0, *c, … Read more

Determine file type in Ruby

There is a ruby binding to libmagic that does what you need. It is available as a gem named ruby-filemagic: gem install ruby-filemagic Require libmagic-dev. The documentation seems a little thin, but this should get you started: $ irb irb(main):001:0> require ‘filemagic’ => true irb(main):002:0> fm = FileMagic.new => #<FileMagic:0x7fd4afb0> irb(main):003:0> fm.file(‘foo.zip’) => “Zip archive … Read more