Join GitHub today
MRI 2.2.2 / JRuby 184.108.40.206 difference given explicit `self` receiver for private method call. #3573
Given the following example:
class Foo def a self.b += 1 end private def b=(v) @b = v end def b @b || 10 end end Foo.new.a == 11
Just an oversight. We try and be compatible as we can but some times things get missed. In this case, MRI is being inconsistent but I sort of remember this change (and I am surprised we did not impl it). Consider a version of a:
def a self.b end
Boom private method. For the sake of += it reasons you are using self so it has access to call both b and b=. I am ok with this but then why does my self.b fail? In any case, we will fix it...
Another thing which bugs me about this behavior and I am only documenting this for fun...It is great this is static analysis feature of the language because:
def a o = self o.b += 1 end
Will not work. It still bugs me because we are calling be against self. If static form of self is ok then why not dynamic one. Perhaps the obvious answer is it would penalize all callsites since you would need to check against self receiver per call...