Issue #14680 has been updated by rab (Rob Biedenharn).


My question is whether this would pass:
~~~ ruby
  def test_uminus
    a = { a: 1, b: 2, c: 3 }

    refute a.frozen?
    assert (-a).frozen?

    a = { a: 1, b: 2, c: 3 }.freeze
    assert_equal a, -a

    # * If the hash is frozen, then return the hash itself.
    fa = { a: 1, b: 2, c: 3 }.freeze
    assert_equal fa, -fa
    assert_equal fa.object_id, (-fa).object_id

    # * If the hash is not frozen, return a frozen copy of it.
    ua = { a: 1, b: 2, c: 3 }
    assert_equal ua, -ua
    refute_equal ua.object_id, (-ua).object_id
  end
~~~
as the code simply `return rb_hash_freeze(hsh);` when *not* `OBJ_FROZEN(hsh)`. 

----------------------------------------
Feature #14680: Adding +@ and -@ to hash and array
https://bugs.ruby-lang.org/issues/14680#change-72468

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Since we have `-@` and `+@` for strings and it's very useful (and reads better than `.freeze`) I'd like to propose adding the same API to hash and array. Especially with constants, linters are always telling me to freeze them, and I'd like to be able to accomplish that with `-@`. I've attached the necessary code to make that happen.

---Files--------------------------------
freeze.patch (3.86 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>