Is it possible to have a keyword argument named `class` or other reserved name in Ruby?

Viewed 389

A lot of Rails tag helpers (e.g. content_tag etc.) use a hash option parameter named class to specify a HTML class.

content_tag(:div, content_tag(:p, "Hello world!"), class: "strong")

For new code I would like to use keyword arguments, but is that possible when one of them is a language keyword?

e.g. for a hypothetical link_tag.

def link_tag(url, class: nil)
  html = ''
  html << '<a href="' << url << '"'
  html << ' class="' << class << '"' if class
  ...


def link_tag(url, opts={})
  html = ''
  html << '<a href="' << url << '"'
  html << ' class="' << opts[:class] << '"' if opts[:class]
  ...
1 Answers
Related