[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Studying the object model

Albert Schlef

1/28/2009 10:44:00 PM

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-....

4 Answers

Satish Talim

1/29/2009 2:26:00 AM

0

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

http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-mod...
taprogramming

Hope that helps.

=97

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



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

> 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-....
>
>

Michael Fellinger

1/29/2009 5:00:00 AM

0

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.

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_Metaprogr...

(it's free, unlike the screencast)

^ manveru

Justin Collins

1/29/2009 5:11:00 AM

0

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

Robert Klemme

1/29/2009 8:13:00 AM

0

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:

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

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