Cache built-in query methods of immutable object

This branch memoizes the `#hash`, `#to_s` and `#inspect` methods automatically since they are based on the instance state, and cannot change since the instance state is immutable.