Skip to content

Instantly share code, notes, and snippets.

@photomattmills
Created August 2, 2015 14:36
Show Gist options
  • Save photomattmills/6a8a37a837de54c258d3 to your computer and use it in GitHub Desktop.
Save photomattmills/6a8a37a837de54c258d3 to your computer and use it in GitHub Desktop.
#! /Users/matt/.rvm/rubies/ruby-2.2.1/bin/ruby
class Foo
attr_accessor :bar
def initialize
puts "initialized"
@bar = 5
end
def bar_divider
@bar /= 5
end
def broken_bar_divider
bar /= 5
end
def other_divider
bar = 4/2
end
def checker
puts bar
end
end
foo = Foo.new # => "initialized"
foo.checker # => 5
p foo.bar_divider # => 1
p foo.other_divider # doesn't actually assign bar
p foo.broken_bar_divider # undefined method '/' for nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment