Thilina Buddhika wrote:
> 
> I am trying to get the names of the methods defined by myself in the top
> scope. I tried it by using
> " self.class.private_instance_methods(false).sort "
> 
> But it gives two additional methods given below.
> inherited
> initialize
> 
> 
> but i want to get only the methods defined by my self. Is there any way
> to solve this ?
> 
> thanks!
> 
> regards,
> buddhika



def hello
end

def goodbye
end

class Dog
end

value = 10

#---------


p Object.private_instance_methods(false)
--->["goodbye", "initialize", "hello"]  #No inherited method anywhere.


method_names = Object.private_instance_methods(false)
my_methods = []

method_names.each do |meth_name|
  if meth_name == 'initialize' or meth_name == 'inherited'
    next
  end

  my_methods << meth_name
end

p my_methods
-->["goodbye", "hello"]
-- 
Posted via http://www.ruby-forum.com/.