Studying the object model

I'm looking for some study aid. I want to understand Ruby's object model
better.

Is there some tool that takes some object as input and shows its
inheritance chain, it's instance and class variables, the singleton
classes and all?

I've already seen some diagrams that explain how OOP work in Ruby, but
I'd still like to see all this in my own eyes.

···

--
Posted via http://www.ruby-forum.com/.

The Pragmatic screencast - Episode 1: Objects and Classes ($5.00, 29
mins)does a good job explaining Ruby object model -

Hope that helps.

···

Satish Talim
RubyLearning
Twitter: http://twitter.com/IndianGuru

On Thu, Jan 29, 2009 at 4:14 AM, Albert Schlef <albertschlef@gmail.com>wrote:

I'm looking for some study aid. I want to understand Ruby's object model
better.

Is there some tool that takes some object as input and shows its
inheritance chain, it's instance and class variables, the singleton
classes and all?

I've already seen some diagrams that explain how OOP work in Ruby, but
I'd still like to see all this in my own eyes.
--
Posted via http://www.ruby-forum.com/\.

There is no interactive tool I know of, but read following:

http://jaoo.dk/ruby-cph-2008/file?path=/jaoo-ruby-cph-2008/slides/Dave_Metaprogramming.pdf

(it's free, unlike the screencast)

^ manveru

···

On Thu, Jan 29, 2009 at 7:44 AM, Albert Schlef <albertschlef@gmail.com> wrote:

I'm looking for some study aid. I want to understand Ruby's object model
better.

Is there some tool that takes some object as input and shows its
inheritance chain, it's instance and class variables, the singleton
classes and all?

I've already seen some diagrams that explain how OOP work in Ruby, but
I'd still like to see all this in my own eyes.

Albert Schlef wrote:

I'm looking for some study aid. I want to understand Ruby's object model
better.

Is there some tool that takes some object as input and shows its
inheritance chain, it's instance and class variables, the singleton
classes and all?

I've already seen some diagrams that explain how OOP work in Ruby, but
I'd still like to see all this in my own eyes.
  
I think you want something more visual than this (?) but you can always just ask Ruby itself:

irb(main):001:0> s = String.new
=> ""
irb(main):002:0> s.class
=> String
irb(main):003:0> s.class.ancestors
=> [String, Enumerable, Comparable, Object, Kernel]
irb(main):004:0> s.public_methods.sort
=> ["%", "*", "+", "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", "", "=", "__id__", "__send__", "all?", "any?", "between?", "bytes", "bytesize", "capitalize", "capitalize!", "casecmp", "center", "chars", "chomp", "chomp!", "chop", "chop!", "class", "clone", "collect", "concat", "count", "crypt", "cycle", "delete", "delete!", "detect", "display", "downcase", "downcase!", "drop", "drop_while", "dump", "dup", "each", "each_byte", "each_char", "each_cons", "each_line", "each_slice", "each_with_index", "empty?", "end_with?", "entries", "enum_cons", "enum_for", "enum_slice", "enum_with_index", "eql?", "equal?", "extend", "find", "find_all", "find_index", "first", "freeze", "frozen?", "grep", "group_by", "gsub", "gsub!", "hash", "hex", "id", "include?", "index", "inject", "insert", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "intern", "is_a?", "kind_of?", "length", "lines", "ljust", "lstrip", "lstrip!", "map", "match", "max", "max_by", "member?", "method", "methods", "min", "min_by", "minmax", "minmax_by", "next", "next!", "nil?", "none?", "object_id", "oct", "one?", "partition", "private_methods", "protected_methods", "public_methods", "reduce", "reject", "replace", "respond_to?", "reverse", "reverse!", "reverse_each", "rindex", "rjust", "rpartition", "rstrip", "rstrip!", "scan", "select", "send", "singleton_methods", "size", "slice", "slice!", "sort", "sort_by", "split", "squeeze", "squeeze!", "start_with?", "strip", "strip!", "sub", "sub!", "succ", "succ!", "sum", "swapcase", "swapcase!", "taint", "tainted?", "take", "take_while", "tap", "test", "to_a", "to_enum", "to_f", "to_i", "to_s", "to_str", "to_sym", "tr", "tr!", "tr_s", "tr_s!", "type", "unpack", "untaint", "upcase", "upcase!", "upto", "zip"]
irb(main):005:0> s.instance_variables
=>
irb(main):006:0> class << s
irb(main):007:1> def test
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> s.singleton_methods
=> ["test"]

-Justin

Here's an easy way to get a visual graph of the currently defined
class hierarchy:

ruby -r pp -e 'tree = Hash.new {|h,k| h[k] = Hash.new(&h.default_proc)}
ObjectSpace.each_object(Class) {|cl| tree[cl.superclass][cl] = tree[cl]}
pp tree[Object]'

Kind regards

robert

···

2009/1/29 Justin Collins <justincollins@ucla.edu>:

Albert Schlef wrote:

I'm looking for some study aid. I want to understand Ruby's object model
better.

Is there some tool that takes some object as input and shows its
inheritance chain, it's instance and class variables, the singleton
classes and all?

I've already seen some diagrams that explain how OOP work in Ruby, but
I'd still like to see all this in my own eyes.

I think you want something more visual than this (?) but you can always just
ask Ruby itself:

--
remember.guy do |as, often| as.you_can - without end