This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [ "a", "b", "c", "d", "e" ] | |
a[6, 1] #=> nil | |
a[5, 1] #=> [] | |
# I don't understand why these are different. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nice | |
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil | |
nil.some_method_nil_doesnt_know_about | |
rescue ex = Exception.new | |
assert_equal NilClass, ex.class | |
assert_match(/NoMethodError/, ex.message) | |
end | |
# not nice | |
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Account | |
attr_reader :name,:balance | |
def initialize(name,balance=100) | |
@name = name | |
@balance = balance | |
end | |
def display_balance(pin_number) | |
puts pin_number == pin ? "Balance: $#{@balance}" : pin_error | |
end |