Hi All
Another Query To bother you all:
1 class Person
2 def *(o)
3 puts “One person meets another”
4 end
5
6 def meets (o)
7 puts “One person meets another”
8 end
9 end
10 a= Person.new
11 b=Person.new
12
13 a * b
14 a.meets b
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
now with above Class the output is:
ruby yet.rb
One person meets another
One person meets another
CASE 1
If I replace Line 13 with this:
a % b #(or any other operator i.e. $ ^ & et al.)
I get the following error :
yet.rb:16: undefined method `%’ for #Person:0x282dbf4 (NoMethodError)
CASE 2
But when i replaced Line 14 with this:
a meets b
the error was this
ruby yet.rb
One person meets another
yet.rb:17: warning: parenthesize argument(s) for future version
yet.rb:17: undefined method `meets’ for main:Object (NoMethodError)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
THE QUERY
If a method is encountered then what is order for locating the method
in class hierarchy?
I mean base to child or reverse?
And regardless of that order why ruby tries to locate the “%” method
from Person (case 1)
while the “meets” method is searched for in Object (case 2)
Thanks in Advance
Raja
Ruby is beautiful!