String: 'hello world'
or "hello world"
Symbol: :hello
or :'hello world'
Differences:
- Symbols are initialized once and are stored in a hash table
a = 'hello'
b = 'hello'
a.object_id == b.object_id #=> false
a = :hello
b = :hello
a.object_id == b.object_id #=> true
- Exceptions hierarchy
- Always rescue
StandardError
. If we rescueException
, there might be a case we rescue a system exception such asNoMemoryError
, or even worse, we cannot exit the system since we rescue the exception caused by system's exit signal. Then the system exception will be swallowed without firing bugs to the developers.
begin
rescue => e # equivalent to rescue StandardError => e
end
- A custom exception should be inherit from
StandardError
. There are 2 ways of declaring
CustomException = Class.new(StandardError)
class CustomException < StandardError
end
There are 5 kinds of mocking in tests.
Dummy object: just a dummy object, used for passing as an argument and doing nothing Stub: Double: Fake: Mock: