Closed jcoyne closed 8 years ago
@no-reply here's how:
find . -name "*.rb" -exec perl -pi -e 'print "# frozen_string_literal: true\n" if $. == 1' {} \;
Definitely a :+1: on this count.
Well, I was all ready to merge, but rbx
is failing:
undefined method
[]' on nil:NilClass. (NoMethodError)`
Looks like the rbx problem was just a CI hiccup.
Note that the generated vocabulary already freezes strings, so the frozen_string_literal
pragma shouldn't cause anything else to freeze. We also can't get rid of the explicit .frozen
method on each string because we need to be explicit for Ruby < 2.3.0, but it's certainly a reasonable thing to do, and we should, indeed, look to see where else it may be useful more generically.
@gkellogg not all strings were frozen. See the keys: https://github.com/ruby-rdf/rdf-vocab/blob/develop/lib/rdf/vocab/dc.rb#L11-L13
True; those should probably be symbols, though. I'll look into that.
This has me curious whether a symbol like :'dc:creator'
instantiates a mutable string literal.
Life's Big Questions :tm:
This has me curious whether a symbol like
:'dc:creator'
instantiates a mutable string literal.
From a theoretical understanding that should just add a new entry to a symbol table. Each time you call #to_s
on the Symbol
object, it will give you back a newly-allocated String
object. Obviously this is implementation-dependent, though.
Note that "foo-bar".to_sym #=> :"foo-bar"
:+1: from me.
@gkellogg @bendiken we should talk about when and how to do this across the suite. See: https://bugs.ruby-lang.org/issues/11473