Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Mike Stramba

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Ruby - "meta method" execute

//
//
// attempt to execute a method indirectly, I don't know if
// it's possible, but I suspect it is, and probably just
// have the syntax wrong
//

   1  
   2  ar = %w(apples bananas oranges)
   3  
   4  print "\n ar.class = #{ar.class}"
   5  
   6  print "\n ar.methods = #{ar.methods.sort}"
   7  puts "======================================================="
   8  
   9  mets = ar.methods.sort
  10  
  11  #
  12  # this doesn't work ... is there a syntax for doing this?
  13  #                       i.e. calling a 'meta' method ?
  14  #
  15  # call each method of 'ar' (an array)
  16  #
  17  #
  18  
  19  mets.each {|method| ar.method} 
  20  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS