Created
November 12, 2014 05:19
-
-
Save enovajuan/a6005bc0cbce063ee5f6 to your computer and use it in GitHub Desktop.
Sanity Check attr_reader vs. attr_accessor -- Ruby
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 SanityCheck | |
attr_reader :locked | |
attr_accessor :implicit_lock | |
def initialize | |
puts "initialize" | |
@locked = true | |
@implicit_lock = false | |
puts "init: #{inspect}" | |
end | |
def check_implicit | |
puts "implicit" | |
locked = !locked | |
implicit_lock = !implicit_lock | |
puts inspect | |
end | |
def check_mixed | |
puts "mixed" | |
@locked = !locked | |
@implicit_lock = !implicit_lock | |
puts inspect | |
end | |
def check_mixed_reversed | |
puts "mixed reversed" | |
locked = !@locked | |
implicit_lock = !@implicit_lock | |
puts inspect | |
end | |
def check_at_symbols | |
puts "symbols" | |
@locked = !@locked | |
@implicit_lock = !@implicit_lock | |
puts inspect | |
end | |
end | |
puts "Each lock should toggle back and forth from test to test..." | |
puts "well not really...." | |
boom = SanityCheck.new | |
boom.check_implicit | |
boom.check_mixed | |
boom.check_mixed_reversed | |
boom.check_at_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment