Hacker News new | ask | show | jobs
by cheald 2374 days ago
You've been able to use `send` to pierce the protected/private restriction forever, so this doesn't particularly change the nature of Ruby's method visibility rules. Now you can just use `self.foo` and it's the same as `self.send :foo`.

    class Foo
      def test
        priv             # works
        self.send(:priv) # works
        self.priv        # doesn't work under ruby 2.6-
        Foo.new.priv     # doesn't work
      end

      private

      def priv
        puts "ran private"
      end
    end
You shouldn't typically need to be using `self` at all, except when it's clarifying or disambiguating, so you shouldn't generally run into that issue. On occasion, though, you add a `self.` prefix to a method call and can break code that was otherwise working, because you've subjected your code to a scope protection that it wasn't subject to before.
1 comments

> You've been able to use `send` to pierce the protected/private restriction forever, so this doesn't particularly change the nature of Ruby's method visibility rules.

I wasn't aware, thanks for pointing that out.

Previously this was a good reason for preferring public_send over send where possible.