Ruby On Rails, Design, Simplicity, Web 2.0, Ajax, Mac and Tons of Pizza.

Mar 03

Ruby Pocket Session # 1 - instance_methods

Posted by Massimo Sgrelli in Ruby on Rails - 3 comments digg this add to delicious

Ruby is a wonderful object oriented programming language. The root class is Object which provides a set of very useful methods among which one called instance_methods. It returns an array with all the public methods of the class or the public methods of the module. Retuning an array you can apply normal array’s operators like this:


class Dog
  attr :bark, true
end

irb> Dog.instance_methods - Object.instance_methods
irb> ["bark", "bark="]

(Ref. See Ruby Pocket Reference p. 38)

Comments

  • marktucks

    Posted on March 03

    Should it be Object.instance_methods?
  • marktucks

    Posted on March 03

    Also, don't mean to crash your post, and don't post these if you were going to in a later post, or even if they are not applicable because you are simply running through Ruby Pocket Reference, but you can also use: methods, private_methods, protected_methods and public_methods :D
  • Massimo Sgrelli

    Posted on March 03

    Sure... Object.instance_methods It was a typing mistake. Thanks Of course you can apply the same principle to every function returning an array as methods, private_methods, protected_methods and public_methods ;)

Post a comment

Categories:

Tags:

Powered by Mephisto, Valid XHTML 1.1, Valid CSS - Supported by Wave Factory