M
Mads Kristensen
Hi.
I was just wondering: does access control not apply to class methods?
When I use the public, private and protected keywords on my instance
methods everything works fine, but when I try to do the same on class
methods they all end up being public anyway.
A small example:
--- Snip ---
#!/usr/bin/ruby
class Foo
public
def Foo._public (x)
puts "Hello in a public way #{x}"
end
protected
def Foo._protected (x)
puts "Hello in a protected way #{x}"
end
private
def Foo._private (x)
puts "Hello in a private way #{x}"
end
end
Foo::_public(1)
Foo::_protected(2)
Foo::_private(3)
--- Snip ---
Running this small program will call all three methods successfully
meaning that the private and protected class methods are called from a
place where _only_ public methods should be available.
So, are there no access control mechanisms for class methods? Or am i
missing domething here?
Best regards,
Mads D. Kristensen
BTW: Thanks to the creators of Ruby for a great little language. Good
work you guys!
I was just wondering: does access control not apply to class methods?
When I use the public, private and protected keywords on my instance
methods everything works fine, but when I try to do the same on class
methods they all end up being public anyway.
A small example:
--- Snip ---
#!/usr/bin/ruby
class Foo
public
def Foo._public (x)
puts "Hello in a public way #{x}"
end
protected
def Foo._protected (x)
puts "Hello in a protected way #{x}"
end
private
def Foo._private (x)
puts "Hello in a private way #{x}"
end
end
Foo::_public(1)
Foo::_protected(2)
Foo::_private(3)
--- Snip ---
Running this small program will call all three methods successfully
meaning that the private and protected class methods are called from a
place where _only_ public methods should be available.
So, are there no access control mechanisms for class methods? Or am i
missing domething here?
Best regards,
Mads D. Kristensen
BTW: Thanks to the creators of Ruby for a great little language. Good
work you guys!