> [Simon wrote:]
>
>> > (c) how invoke "hidden" methods?
>>
>> Simply send the message a method invocation would produce yourself:
>>
>> irb(main):003:0> 5.send(:rand)
>> => 0.748920713318512
>
> Whoa! So private methods can be called after all???!
>
> Not the end of the world, I guess. After all, Python doesn't support
> private methods at all, right? Still a bit odd in my opinion.
>
> Is there any reason why Ruby allows private methods to be invoked like
> this? (rather than provide a tidy alternative for problems like mine).

It may help to think of it not as a method being invoked, rather a message
being sent.  The object decides how it wishes to respond to that message.

After all, you can't invoke a method that doesn't exist, but you can get a
response back from a message that doesn't have a corresponding method, if
you get my drift.

  class X
    def method_missing(sym, *args)
      5
    end
  end

  x = X.new
  x.foo                # -> 5
  x.bar                # -> 5
  x.quux               # -> 5
  x.method(:foo)       # -> NameError: undefined method 'foo'
  x.nil?               # -> false

Gavin