Skip to content

Instantly share code, notes, and snippets.

@crux
Created March 28, 2012 16:16
Show Gist options
  • Save crux/2227909 to your computer and use it in GitHub Desktop.
Save crux/2227909 to your computer and use it in GitHub Desktop.
ruby assignment method visibility
#!/usr/bin/env ruby
class A
def a=(x)
puts "-- a=(#{x})"
@a = x
end
def a puts "-- a" @a
end
def b puts "-- b"
a # executes A#a
end
def b=(x)
puts "-- b=(#{x})"
a=(x) # Why does this NOT execute A#a=
end
end
a = A.new
puts a.a # nil
a.a = 321
puts a.a # 321
puts a.b # 321
a.b = 123
puts a.a # 321???
puts a.b # 321?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment