Skip to content

Instantly share code, notes, and snippets.

View jbevarts's full-sized avatar
💭
In the cloud

Jerry Evarts jbevarts

💭
In the cloud
  • Las Vegas, NV
View GitHub Profile
@jbevarts
jbevarts / gist:5776369
Created June 13, 2013 18:57
Slicing Arrays
a = [ "a", "b", "c", "d", "e" ]
a[6, 1] #=> nil
a[5, 1] #=> []
# I don't understand why these are different.
@jbevarts
jbevarts / gist:5774520
Last active December 18, 2015 11:19
Begin/rescue/end
# 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
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