views:

33

answers:

1

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

A: 

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

nessence
Thank you! I started learning from Rails, and it has been a steep learning curve to learn Ruby the language itself for me. I need that so I don't need to keep depending on others when the plugin I used stuck. I'd be happy if you could point me to more resources.
jaycode
http://github.com/edgecase/ruby_koans is a pretty interesting way to learn the edge cases of Ruby.
Jason Noble
@jaycode: That book is really all you need for Ruby. If you've mastered what's in that book, the next steps are looking at the source code of projects like Rails. At that point, you begin treating the book as a reference instead of a guide. Last, is the Ruby command-line interface, 'irb'. Just open a terminal and run irb -- then you can type and run any Ruby code you'd like. I'm sure you'll find things like "Unit Testing" along the way.
nessence