Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

You can still do that luckily!

In Rails and other Ruby frameworks that existed before Ruby had KWARGs (named parameters) they would get around this by using Ruby's implicit destructuring of hashes if they're the last argument in a method. So this could be done by doing something like this. 

def sprite_helper(options = {})
  x = options[:x]
  y = options[:y]
  width = options[:width]
  height = options[:height]
  color = options[:color]
end
sprite_helper x: 10, y: 10, width: 100, height: 100, color: [0, 0, 0]


The downsides of this approach is you lose the ability to make certain arguments required without doing your own checking of the options hash and raising errors, but the upside is that it still allows for default arguments and allows you to pass a hash in as arguments in any order.