0.0
No commit activity in last 3 years
No release in over 3 years
Provides some syntactic sugar of implicitly frozen objects and an freezing operator useful for example in class constants.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.5.2
>= 0.12.1
 Project Readme

Frozen Objects

frozen-objects provides some syntactic sugar of implicitly frozen objects and an freezing operator useful especially in class constants. Dont't find anything useful or some rocket science here. It's just sugar only, nothing more, nothing less.

require "frozen-objects"

class Foo
    SOME_ARRAY = Frozen::Array[:a, :b]   
    # ...or any other Array constructing methods
    SOME_HASH = Frozen::Hash[:a => :b]   
    # ...or any other Hash constructing methods
    SOME_STRING = Frozen::String::new("bar")
end

Foo::SOME_ARRAY.frozen?     # will return true
Foo::SOME_HASH.frozen?      # will return true
Foo::SOME_STRING.frozen?    # will return true

All attempts to modify these objects will fail on RuntimeError. Objects are also reported as frozen. From other points of view they are "normal" and fully compatible with Ruby implicitly non-frozen objects.

Freezing Operator

Frozen module defines also frozen operator. It's intended for nice and simple freezing whatever. Consider example above:

require "frozen-objects"

class Foo
    SOME_ARRAY = Frozen << [:a, :b]
    SOME_HASH = Frozen << {:a => :b}
    SOME_STRING = Frozen << "bar"
    
    WHATEVER = Frozen << SomeClass::new
end

Both methods are equivalent.

Copyright

Copyright © 2011 – 2015 Martin Poljak. See LICENSE.txt for further details.