For example a file in active_support/core_ext/exception.rb
it started with:
module ActiveSupport
if RUBY_VERSION >= '1.9'
FrozenObjectError = RuntimeError
else
FrozenObjectError = TypeError
end
end
Then continued with class Exception code
what does it mean? What do you use FrozenObjectError, RuntimeError, and TypeError objects for? How do I know where they are initialized? why do we need these lines of code?
Could you recommend me a good book to learn about this, please?
Thanks
Yes — every line in Ruby is within an object, even the global scope. For your example, the ‘error’ for violating a Frozen Object is set based on what version is being run. In 1.9 it’s a runtime exception whereas prior is a type error (this has to do with changes introduced in 1.9). This makes the exception as descriptive as possible.
Programming Ruby is very elegant at explaining the language:
Programming Ruby