Private method called ?
Published almost 7 years ago

Today is one of the times I hate the way ruby implements it’s own Object oriented concepts – No flames invited. I love ruby. But this is just one of “those” moments..

class Person
  def method_missing(method_id, *args)
    puts "#{method_id} called with #{args.inspect}"


class Indian < Person
  def secret
    puts "We are nuts"

i =
puts i.secret("Fuck")

# $ ruby crap.rb
# secret called with ["Fuck"]
# true

Here, I’d expect ruby to throw up with “private method `secret’ called for # (NoMethodError)” error. But it just leans over to method_missing(). That kinda makes sense, considering Ruby completely hides private methods and throws NoMethodError. But playing around with this a little more, I realize that method_missing() acts the same way, even if it’s defined public or protected or private. So why not just use these visibility scoping to make it act a little better – e.g. lean over to parent’s class method_mising() for a private method called only if method_missing() visibility is public – and some more similar rules ?