Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make {"foo": 1} also be a named tuple #2795

Merged
merged 1 commit into from
Jun 10, 2016
Merged

Conversation

asterite
Copy link
Member

Fixes #2631

This makes "foo bar": 1 (string literal, colon, expression) mean a named tuple literal everywhere now, and only => can be used for a hash literal.

The places where this is applicable is:

  • Named tuples: {"foo bar": 1}
  • Named tuple types: x : {"foo bar": Int32}
  • NamedTuple instantiation: NamedTuple("foo bar": Int32)
  • Calls: foo bar: 1, "baz qux": 3

I tried using this new syntax in html_builder and it worked well:

require "./src/html_builder"

string =
  HTML.build do
    html do
      body do
        a(href: "http://crystal-lang.org", "data-awesome": "true") do
          text "crystal is awesome"
        end
      end
    end
  end

puts string # => "<html><body><a href="http://crystal-lang.org" data-awesome="true">crystal is awesome</a></body></html>"

This is a breaking change, but it makes things more consistent, and allows things like the above.

@asterite asterite merged commit 3acaca7 into master Jun 10, 2016
@asterite asterite deleted the feature/named_argument_string branch June 13, 2016 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants