Symbol.to_proc overrides private

Why is that? It seems unexpected.

class A
def initialize(a)
@foo = a
end

def sort_key
-@foo
end

def inspect
@foo.to_s
end

private :sort_key
end

b = [1,2,3,4,5].map {|x| A.new(x)}

p b
p b.sort_by(&:sort_key) # works
p b.sort_by {|x| x.sort_key} # private method called error

martin

Maybe it invokes send internally? send doesn’t respect privacy, does it?

Hal

Yeah, or the C equivalent thereof. I was more wondering whether it’s
an unintended consequence or if that’s the desired behaviour any time
you access a method via its symbol.

martin

On Sat, Sep 28, 2013 at 12:04 AM, Martin DeMello
[email protected] wrote:

Yeah, or the C equivalent thereof. I was more wondering whether it’s
an unintended consequence or if that’s the desired behaviour any time
you access a method via its symbol.

I guess it’s the former - maybe even worth a bug report (even if it
gets closed).

Kind regards

robert

Seems to be already fixed in 2.0.0-p247

martin

On Sun, Sep 29, 2013 at 9:07 AM, Robert K.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs