Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[EVALUATION] - E03 - jamLang Evaluation Case Applied to Ruby

3 views
Skip to first unread message

Ilias Lazaridis

unread,
Mar 18, 2005, 9:37:36 AM3/18/05
to
[EVALUATION] - E02 - Nitro, a Ruby Based WebFramework
http://groups-beta.google.com/group/comp.lang.ruby/msg/0fb8b0824d4fbaec

-

The above thread showed finally the need to split the evaluation down
into smaller chunks.

Here is a simple evaluation template (first part) which can be applied
to the Ruby language:

http://lazaridis.com/case/lang/index.html

If you like, please post the most elegant solutions (either to sections
or to the whole document).

I will collect the results and write them down in a document, which will
compare ruby with other languages.

This document can serve as an flash-start (for people which simply like
to take a look on ruby).

http://lazaridis.com/case/lang/ruby.html

.

--
http://lazaridis.com

Martin DeMello

unread,
Mar 18, 2005, 11:29:33 AM3/18/05
to
Ilias Lazaridis <il...@lazaridis.com> wrote:
>
> The above thread showed finally the need to split the evaluation down
> into smaller chunks.
>
> Here is a simple evaluation template (first part) which can be applied
> to the Ruby language:
>
> http://lazaridis.com/case/lang/index.html

Okay, that's a neat bit of work. Here's a quick solution (ruby makes
most of this fairly trivial):

# here's your basic talker class

class Talker
def sayHello
puts "Hello world"
end
end

# __FILE__ == $0 means that the program is being run directly
# rather than 'require'd from another file

if __FILE__ == $0
talker = Talker.new
talker.sayHello
end

# one-pass interpreter, and you can reopen classes
# so let's just continue

# here are the two instance variables added to the class, complete with
# autogenerated getters and setters

class Talker
attr_accessor :name, :age

def initialize(name, age)
@name, @age = name, age
end

# following the spec, though say_name is more rubyish
def sayYourName
puts @name
end

def sayYourAge
puts @age
end
end

# now note that our object 'talker' has access to the new methods in its
# class

if __FILE__ == $0
# note that we aren't breaking encapsulation and accessing the vars directly;
# the setter methods are called name= and age=, and the getters are called
# name and age
talker.name = "Just another talker"
talker.age = 1
talker.sayYourName
talker.sayYourAge
end

# reflection
class Talker

# simple

def sayYourClassName
puts self.class.name # the 'self' is optional here
end

# objects know nothing about the variables that are bound to them
# (a variable name is not the name of the instance anyway). The
# closest you can come to the "name" of an object is it's object id, so...
def sayYourInstanceName
puts object_id # again, you could say self.object_id if you prefer
end

# advanced

# caller returns a stack (array) of strings of the form
# file:linenumber in `method'
# so we extract the most recent one and parse the method name out
# code from PLEAC
def thisMethodName
caller[0] =~ /in `([^']+)'/ ? $1 : '(anonymous)';
end

# string interpolation in action - the bit between the #{} can be
# any valid expression; to_s will be called on the result and
# interpolated into the string
def sayHelloAdvanced
puts "#{thisMethodName}: Hello World"
end

# expert
def sayYourClassDefinition
puts "Class:"
sayYourClassName

# %{} is another way to write a string literal
# (looks neat for multiline strings)
# we use the standard 'inspect' method to print out arrays of
# method names in a ["meth1", "meth2", ...] format
puts %{
Methods:
public:
#{public_methods.inspect}
protected
#{protected_methods.inspect}
private:
#{private_methods.inspect}
non-inherited:
#{(methods - self.class.superclass.instance_methods).inspect}

Instance Variables:
#{instance_variables.inspect}
}

# note that the instance variables belong to the *instance*, not
# to the class, so they're not technically part of the class
# definition. the following code is illustrative:
#
# class A
# attr_accessor :foo, :bar # defines getters and setters
# end
#
# a = A.new
# p a.instance_variables # => []
# a.foo = 10
# p a.instance_variables # => ["@foo"]
# b = A.new
# p b.instance_variables # => []
end

def sayYourClassCode
puts "Sadly, you cannot introspect the source code from within a program"
# though see http://rubyforge.org/projects/parsetree/
# for a way to get at the parsed AST
end
end

# testing it out

if __FILE__ == $0
talker.sayHelloAdvanced
talker.sayYourClassName
talker.sayYourClassDefinition
talker.sayYourClassCode
end

Hope this helps.

martin

Ilias Lazaridis

unread,
Mar 20, 2005, 12:58:37 PM3/20/05
to
Martin DeMello wrote:
> Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>The above thread showed finally the need to split the evaluation down
>>into smaller chunks.
>>
>>Here is a simple evaluation template (first part) which can be applied
>>to the Ruby language:
>>
>>http://lazaridis.com/case/lang/index.html
>
> Okay, that's a neat bit of work. Here's a quick solution (ruby makes
> most of this fairly trivial):

I apologize for the late answer.

> # here's your basic talker class
>
> class Talker
> def sayHello
> puts "Hello world"
> end
> end

ok

> # __FILE__ == $0 means that the program is being run directly
> # rather than 'require'd from another file
>
> if __FILE__ == $0
> talker = Talker.new
> talker.sayHello
> end

Assuming I placethe code into the file "talker.rb".

from the command-line, i like to start it, e.g. with "ruby talker.rb"

I miss a "main" directive / function / object.

something like:

def main


talker = Talker.new
talker.sayHello
end

> # one-pass interpreter, and you can reopen classes
> # so let's just continue

[sidenote: I don't understand this]

> # here are the two instance variables added to the class, complete with
> # autogenerated getters and setters

very nice!

> class Talker
> attr_accessor :name, :age

can I write?:

attr_accessor :name
attr_accessor :age

> def initialize(name, age)
> @name, @age = name, age
> end

Is this the constructor?

I assume I can write

def initialize(name, age)
@name = name
@age = age
end

> # following the spec, though say_name is more rubyish
> def sayYourName
> puts @name
> end

can I write?: def sayYourName puts @name end

> def sayYourAge
> puts @age
> end
> end

ok

> # now note that our object 'talker' has access to the new methods in its
> # class
>
> if __FILE__ == $0
> # note that we aren't breaking encapsulation and accessing the vars directly;
> # the setter methods are called name= and age=, and the getters are called
> # name and age

very(!) nice!

> talker.name = "Just another talker"
> talker.age = 1
> talker.sayYourName
> talker.sayYourAge
> end

ok

> # reflection
[...]

seperate message will follow.

.

--
http://lazaridis.com

Douglas Livingstone

unread,
Mar 20, 2005, 7:07:25 PM3/20/05
to
On Mon, 21 Mar 2005 02:59:53 +0900, Ilias Lazaridis <il...@lazaridis.com> wrote:
> Martin DeMello wrote:
> > Ilias Lazaridis <il...@lazaridis.com> wrote:
> >
> > # __FILE__ == $0 means that the program is being run directly
> > # rather than 'require'd from another file
> >
> > if __FILE__ == $0
> > talker = Talker.new
> > talker.sayHello
> > end
>
> Assuming I placethe code into the file "talker.rb".
>
> from the command-line, i like to start it, e.g. with "ruby talker.rb"
>
> I miss a "main" directive / function / object.

You can think of the whole file as "main". The code will be read from
top to bottom.

> > # one-pass interpreter, and you can reopen classes
> > # so let's just continue
>
> [sidenote: I don't understand this]

Example:

# first time setting the class
class Talker
attr_accessor :name

def initialize(name)
@name = name
end

end

talker = Talker.new('Bob')
puts talker.name

# reopen the class to add sayYourName
class Talker


def sayYourName
puts @name
end

end

talker.sayYourName


The output is:

Bob
Bob


> > class Talker
> > attr_accessor :name, :age
>
> can I write?:
>
> attr_accessor :name
> attr_accessor :age

yes

> > def initialize(name, age)
> > @name, @age = name, age
> > end
>
> Is this the constructor?
>
> I assume I can write
>
> def initialize(name, age)
> @name = name
> @age = age
> end

yes

> > # following the spec, though say_name is more rubyish
> > def sayYourName
> > puts @name
> > end
>
> can I write?: def sayYourName puts @name end

You need to add semicolons if you want to put more than one line on a line:

def sayYourName; puts @name; end

hth,
Douglas


Martin DeMello

unread,
Mar 21, 2005, 4:58:05 AM3/21/05
to
Ilias Lazaridis <il...@lazaridis.com> wrote:
>
> > # one-pass interpreter, and you can reopen classes
> > # so let's just continue
>
> [sidenote: I don't understand this]

The ruby interpreter is one-pass insofar as it takes a single pass through
the file, from top to bottom, building and executing an abstract syntax tree
as it goes. Anything enclosed in a def...end block (and a few other
delayed-evaluation constructs like lambda) gets converted into a 'callable'
block of code, the rest is just executed. That's how attr_accessor works,
incidentally - it's just a piece of code that runs inside a class's context
and generates methods when it's executed. Try the following:

class Foo
def say_hello
puts "hello world"
end

puts "hi, this is the reader"
end

a = Foo.new
a.say_hello

the first puts statement gets executed when say_hello is called; the second
one is not inside a def statement, and so gets executed when the interpreter
gets to it.

Hence the lack of a main() method - in a sense, the whole fine is a main(),
since the entry point is the top of the file (comes in real handy when
writing quick imperative scripts - you aren't forced to define a class just
because Ruby is a pure OO language).

Hence the if __FILE__ == $0 blocks - if the file is not being run directly,
the condition fails, and the whole block is skipped.

As for reopening classes, you can modify a class at runtime (add/delete
methods, mix in a module), and any objects belonging to the class inherit
those modifications (rather trivially, since they look up methods in the
class). But, since this is a one pass interpreter, those changes come into
effect at the time the reader reads them, and so the object "changes" in the
middle of its lifecycle.

martin

Ilias Lazaridis

unread,
Mar 21, 2005, 9:10:56 AM3/21/05
to
Douglas Livingstone wrote:
> On Mon, 21 Mar 2005 02:59:53 +0900, Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>Martin DeMello wrote:
>>
>>>Ilias Lazaridis <il...@lazaridis.com> wrote:
>>>
>>># __FILE__ == $0 means that the program is being run directly
>>># rather than 'require'd from another file
>>>
>>>if __FILE__ == $0
>>> talker = Talker.new
>>> talker.sayHello
>>>end
>>
>>Assuming I placethe code into the file "talker.rb".
>>
>>from the command-line, i like to start it, e.g. with "ruby talker.rb"
>>
>>I miss a "main" directive / function / object.
>
> You can think of the whole file as "main". The code will be read from
> top to bottom.

I understand.

This means that ruby is _not_ strictly Object Oriented.

And this means that I can drop the "if __FILE__ [...]" construct.

I like both points.

-

I assume I can launch my application with "ruby talker.rb".

>>># one-pass interpreter, and you can reopen classes
>>># so let's just continue
>>
>>[sidenote: I don't understand this]
>
> Example:
>
> # first time setting the class
> class Talker
> attr_accessor :name
>
> def initialize(name)
> @name = name
> end
>
> end
>
> talker = Talker.new('Bob')
> puts talker.name
>
> # reopen the class to add sayYourName
> class Talker
> def sayYourName
> puts @name
> end
> end
>
> talker.sayYourName
>
>
> The output is:
>
> Bob
> Bob

[I think I understand, but will postpone this construct]

>>>class Talker
>>> attr_accessor :name, :age
>>
>>can I write?:
>>
>>attr_accessor :name
>>attr_accessor :age
>
> yes

ok

>>> def initialize(name, age)
>>> @name, @age = name, age
>>> end
>>
>>Is this the constructor?
>>
>>I assume I can write
>>
>> def initialize(name, age)
>> @name = name
>> @age = age
>> end
>
> yes

ok

>>> # following the spec, though say_name is more rubyish
>>> def sayYourName
>>> puts @name
>>> end
>>
>>can I write?: def sayYourName puts @name end
>
> You need to add semicolons if you want to put more than one line on a line:
>
> def sayYourName; puts @name; end

ok

> hth,
> Douglas

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Mar 21, 2005, 9:30:24 AM3/21/05
to
Martin DeMello wrote:
> Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>># one-pass interpreter, and you can reopen classes
>>># so let's just continue
>>
>>[sidenote: I don't understand this]
>
> The ruby interpreter is one-pass insofar as it takes a single pass through
[...] - (interpreter, dynamic mixins, ...)

Thank you for you explanations.

I've understood now everything.

Altough I'm excited about some contructs, I must postpone their discussion.

I'll come back to them soon.

.

--
http://lazaridis.com

Martin Ankerl

unread,
Mar 21, 2005, 9:38:41 AM3/21/05
to
>> You can think of the whole file as "main". The code will be read from
>> top to bottom.
[...]

> This means that ruby is _not_ strictly Object Oriented.

Ruby is not strictly OO, but not for the reason you think. Here is a
nice explenation why:
http://www.rubycentral.com/book/classes.html#S3

> And this means that I can drop the "if __FILE__ [...]" construct.

__FILE__ is the name of the current source file.
$0 is the name of the top-level ruby program being executed.

So this construct just checks if this the source file is the file that
is executed directly with e.g. 'ruby talker.rb', and only if this is the
case, the codeblock will be executed.


martinus

Ilias Lazaridis

unread,
Mar 21, 2005, 4:28:29 PM3/21/05
to
Martin Ankerl wrote:
>>> You can think of the whole file as "main". The code will be read from
>>> top to bottom.
> [...]
>
>> This means that ruby is _not_ strictly Object Oriented.
>
> Ruby is not strictly OO, but not for the reason you think. Here is a
> nice explenation why:
> http://www.rubycentral.com/book/classes.html#S3

impressive.

>> And this means that I can drop the "if __FILE__ [...]" construct.
>
> __FILE__ is the name of the current source file.

ok, here i guessed right (intuitive naming).

> $0 is the name of the top-level ruby program being executed.

here i thought that "$0" represents "NULL".

$0 => main-file (or entry-file, or top-level file, or top-level program)

> So this construct just checks if this the source file is the file that
> is executed directly with e.g. 'ruby talker.rb', and only if this is the
> case, the codeblock will be executed.

Ok, now it's clear.

> martinus

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Mar 22, 2005, 8:38:11 PM3/22/05
to

The first result is available.

I would like to setup ruby at this point, to add the installation steps
to the document.

Can one suggest me the simplest possible installation (one-click)?

One for Windows and one for Linux (if possible similar in content)?

.

--
http://lazaridis.com

Tom Copeland

unread,
Mar 22, 2005, 10:12:05 PM3/22/05
to
On Wed, 2005-03-23 at 10:39 +0900, Ilias Lazaridis wrote:
> Can one suggest me the simplest possible installation (one-click)?
>
> One for Windows and one for Linux (if possible similar in content)?

Installer for Windows is here:

http://rubyforge.org/frs/?group_id=167

and for Linux:

http://rubyforge.org/frs/?group_id=426

Yours,

Tom


Ilias Lazaridis

unread,
Mar 23, 2005, 8:58:49 PM3/23/05
to
Martin DeMello wrote:
> Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>The above thread showed finally the need to split the evaluation down
>>into smaller chunks.
>>
>>Here is a simple evaluation template (first part) which can be applied
>>to the Ruby language:
>>
>>http://lazaridis.com/case/lang/index.html
>
> Okay, that's a neat bit of work. Here's a quick solution (ruby makes
> most of this fairly trivial):
>
> # here's your basic talker class
>
> class Talker
> def sayHello
> puts "Hello world"
> end
> end

I will make a slight addition:

The application main code will be alternatively entered in a seperate
file, main.rb:

> talker = Talker.new
> talker.sayHello

How does "main.rb" gets knowledge about "talker.rb" ?

-

[...]


> # string interpolation in action - the bit between the #{} can be
> # any valid expression; to_s will be called on the result and
> # interpolated into the string
> def sayHelloAdvanced
> puts "#{thisMethodName}: Hello World"
> end

[...]

"#" is used as a comment marker _and_ partly within code.

Can I use another comment marker?

Can I write "puts "#{thisMethodName}: Hello World"" in an different
manner, without the use of "#"?

.

--
http://lazaridis.com

Jacob Fugal

unread,
Mar 24, 2005, 1:19:05 PM3/24/05
to
On Thu, 24 Mar 2005 10:59:50 +0900, Ilias Lazaridis <il...@lazaridis.com> wrote:
> Martin DeMello wrote:
> > # here's your basic talker class
> >
> > class Talker
> > def sayHello
> > puts "Hello world"
> > end
> > end
>
> I will make a slight addition:
>
> The application main code will be alternatively entered in a seperate
> file, main.rb:
>
> > talker = Talker.new
> > talker.sayHello
>
> How does "main.rb" gets knowledge about "talker.rb" ?

Put the code for the Talker class in a separate file then 'require'
that file in main.rb. For example, if the Talker class were in
talker.rb then I'd have:

require 'talker'

talker = Talker.new
talker.sayHello

for my main.rb. Note that the require statement does not need the .rb
suffix on the file containing the class.


> > # string interpolation in action - the bit between the #{} can be
> > # any valid expression; to_s will be called on the result and
> > # interpolated into the string
> > def sayHelloAdvanced
> > puts "#{thisMethodName}: Hello World"
> > end
>

> "#" is used as a comment marker _and_ partly within code.
>
> Can I use another comment marker?

No. To my knowledge there is only the one comment syntax in ruby.

> Can I write "puts "#{thisMethodName}: Hello World"" in an different
> manner, without the use of "#"?

Sure. #{thisMethodName} in a string literal simply calls .to_s on the
enclosed expression and inserts it at the designated location. So we
can pull that out such:

puts thisMethodName.to_s + ": Hello World"

The + operator performs concatenation when its arguments are strings.

Jacob Fugal


Martin Ankerl

unread,
Mar 24, 2005, 1:30:39 PM3/24/05
to
>>Can I use another comment marker?
> No. To my knowledge there is only the one comment syntax in ruby.

You can use e.g.

=begin
bla bla
bla
=end


martinus

James Edward Gray II

unread,
Mar 24, 2005, 1:33:42 PM3/24/05
to
On Mar 24, 2005, at 12:19 PM, Jacob Fugal wrote:

>> "#" is used as a comment marker _and_ partly within code.
>>
>> Can I use another comment marker?
>
> No. To my knowledge there is only the one comment syntax in ruby.

Ruby has a multiline comment syntax:

=begin
This is a comment.
=end

Just FYI.

James Edward Gray II

Ilias Lazaridis

unread,
Mar 24, 2005, 10:57:31 PM3/24/05
to
Martin DeMello wrote:
> Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>The above thread showed finally the need to split the evaluation down
>>into smaller chunks.
>>
>>Here is a simple evaluation template (first part) which can be applied
>>to the Ruby language:
>>
>>http://lazaridis.com/case/lang/index.html
>
> Okay, that's a neat bit of work. Here's a quick solution (ruby makes
> most of this fairly trivial):
>
> # here's your basic talker class
[...]

preliminary draft:

http://lazaridis.com/case/lang/ruby.html

> # reflection
> class Talker
>
> # simple
>
> def sayYourClassName
> puts self.class.name # the 'self' is optional here
> end

omitting "self" (puts class.name) leads to an error

> # objects know nothing about the variables that are bound to them
> # (a variable name is not the name of the instance anyway). The
> # closest you can come to the "name" of an object is it's object id, so...
> def sayYourInstanceName
> puts object_id # again, you could say self.object_id if you prefer
> end

ok

> # advanced
>
> # caller returns a stack (array) of strings of the form
> # file:linenumber in `method'
> # so we extract the most recent one and parse the method name out
> # code from PLEAC
> def thisMethodName
> caller[0] =~ /in `([^']+)'/ ? $1 : '(anonymous)';
> end

I understand the concept.

is there possibly a more direct solution available, with cleaner code
and a stable/higher execution speed?

> # string interpolation in action - the bit between the #{} can be
> # any valid expression; to_s will be called on the result and
> # interpolated into the string
> def sayHelloAdvanced
> puts "#{thisMethodName}: Hello World"
> end

ok

> # expert
> def sayYourClassDefinition
> puts "Class:"
> sayYourClassName

puts "Class #{self.class.name}" >> Class Talker

but

puts "Class #{sayYourClassName}" >> Talker Class
puts "Class " + sayYourClassName.to_s >> Talker Class

why?

> # %{} is another way to write a string literal

#{} - inside strings
%{} - outside of strings

> # (looks neat for multiline strings)
> # we use the standard 'inspect' method to print out arrays of
> # method names in a ["meth1", "meth2", ...] format
> puts %{
> Methods:
> public:
> #{public_methods.inspect}
> protected
> #{protected_methods.inspect}
> private:
> #{private_methods.inspect}
> non-inherited:
> #{(methods - self.class.superclass.instance_methods).inspect}
>
> Instance Variables:
> #{instance_variables.inspect}
> }

Can I get somehow a more precise reflection of the class definition
(output similar to the original class-def, excluding code)?

> # note that the instance variables belong to the *instance*, not
> # to the class, so they're not technically part of the class
> # definition. the following code is illustrative:
> #
> # class A
> # attr_accessor :foo, :bar # defines getters and setters
> # end
> #
> # a = A.new
> # p a.instance_variables # => []
> # a.foo = 10
> # p a.instance_variables # => ["@foo"]
> # b = A.new
> # p b.instance_variables # => []
> end

ok

> def sayYourClassCode
> puts "Sadly, you cannot introspect the source code from within a program"
> # though see http://rubyforge.org/projects/parsetree/
> # for a way to get at the parsed AST
> end

ok

> end
>
> # testing it out
>
> if __FILE__ == $0
> talker.sayHelloAdvanced
> talker.sayYourClassName
> talker.sayYourClassDefinition
> talker.sayYourClassCode
> end
>
> Hope this helps.

very much!

thank you for your efforts.

> martin

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Mar 25, 2005, 8:26:08 PM3/25/05
to
[from an answer which showed up as a seperate thread]

James Edward Gray II wrote:
> Begin forwarded message:


>
>>> # reflection
>>> class Talker
>>> # simple
>>> def sayYourClassName
>>> puts self.class.name # the 'self' is optional here
>>> end
>>
>> omitting "self" (puts class.name) leads to an error
>

> I checked this one myself, because it surprised me when you said it.
> You're right of course. I'm assuming it's because class is a method
> name and a Ruby keyword.

ok

>>> # advanced
>>> # caller returns a stack (array) of strings of the form #
>>> file:linenumber in `method'
>>> # so we extract the most recent one and parse the method name out
>>> # code from PLEAC
>>> def thisMethodName
>>> caller[0] =~ /in `([^']+)'/ ? $1 : '(anonymous)';
>>> end
>>
>> I understand the concept.
>>
>> is there possibly a more direct solution available, with cleaner code
>> and a stable/higher execution speed?
>

> Have you measured it and proven it too slow? Remember, premature
> optimization is the root of all evil in programming. ;)
>
> I'm not sure what you consider "clean", but getting rid of the ternary
> operator may make it a little more readable:
>
> if caller[0] =~ /in `([^']+)'/ then $1 else '(anonymous)' end

I meant something direct like:

caller.active_method

>>> # expert
>>> def sayYourClassDefinition
>>> puts "Class:"
>>> sayYourClassName
>>
>> puts "Class #{self.class.name}" >> Class Talker
>>
>> but
>>
>> puts "Class #{sayYourClassName}" >> Talker Class
>> puts "Class " + sayYourClassName.to_s >> Talker Class
>>
>> why?
>

> In the first example, you're asking Ruby for the class name, which you
> add to a string that gets printed by the local call to puts. In the
> other two, you're calling a method that prints the class name
> immediately.

Of course [I've overseen the print statements].

> Then the local puts prints "Class " and the return value
> from the method call, which isn't meaningful in this context.

ok

>>> # %{} is another way to write a string literal
>>
>> #{} - inside strings
>> %{} - outside of strings
>

> No, these are not equivalent. #{...} is for interpolating Ruby code
> inside a string. %{...} defined a double quoted string, without the
> quotes:
>
> %{This is a string. I can use "quotes" in here. And #{"interpolate"}
> values.}

ok, now I understand.

%{} => string
#{} => string interpolation of code

>>> # (looks neat for multiline strings)

[...]


>>> }
>>
>> Can I get somehow a more precise reflection of the class definition
>> (output similar to the original class-def, excluding code)?
>

> I don't believe so, no. Remember that a Ruby class can be reopened
> and definitions added to it. That means a class could be built up
> from many places.
>
> Ruby does have a means to get it to store the source code it reads,
> but I don't believe that's what you were asking for.

you're right.

-

I will try to work this out myself.

Where can I find the following information?:

* An UML diagramm (or another visual representation) of the ruby
class-model.

* A deep (but compact) description of the reflection/introspection api's.

> James Edward Gray II

.

--
http://lazaridis.com

Florian Gross

unread,
Mar 25, 2005, 9:05:58 PM3/25/05
to
Ilias Lazaridis wrote:

> Where can I find the following information?:
>
> * An UML diagramm (or another visual representation) of the ruby
> class-model.

I've generated this one automatically:

http://flgr.0x42.net/class-graph.png

Note that it is quite large and not too pretty, though.

> * A deep (but compact) description of the reflection/introspection api's.

Well, the Pickaxe book (slightly outdated version is available online
for free, new issue with lots of new material can be ordered online)
contains that among much other information and is a pretty interesting
read. See

http://www.rubycentral.com/book/ (first issue)
http://phrogz.net/ProgrammingRuby/ (first issue with Wiki for changes)
http://www.pragmaticprogrammer.com/titles/ruby/index.html (second issue)
http://www.amazon.com/exec/obidos/tg/detail/-/0974514055/ (second issue)

I'd recommend ordering the second issue from the pragmatic guys as it
contains detailed information that will be useful for evaluating Ruby in
depth.

Ilias Lazaridis

unread,
Mar 25, 2005, 11:56:02 PM3/25/05
to
Florian Gross wrote:
> Ilias Lazaridis wrote:
>
>> Where can I find the following information?:
>>
>> * An UML diagramm (or another visual representation) of the ruby
>> class-model.
>
> I've generated this one automatically:
>
> http://flgr.0x42.net/class-graph.png

with which tool have you generated this?

> Note that it is quite large and not too pretty, though.

This is a nice overview.

Does anyone has the detailed model of the core class-model?

>> * A deep (but compact) description of the reflection/introspection
>> api's.
>
> Well, the Pickaxe book (slightly outdated version is available online
> for free, new issue with lots of new material can be ordered online)
> contains that among much other information and is a pretty interesting
> read. See
>
> http://www.rubycentral.com/book/ (first issue)
> http://phrogz.net/ProgrammingRuby/ (first issue with Wiki for changes)
> http://www.pragmaticprogrammer.com/titles/ruby/index.html (second issue)
> http://www.amazon.com/exec/obidos/tg/detail/-/0974514055/ (second issue)
>
> I'd recommend ordering the second issue from the pragmatic guys as it
> contains detailed information that will be useful for evaluating Ruby in
> depth.

thank you for the information.

I need at this point only reference of the reflection/introspection api.

I cannot locate it.

.

--
http://lazaridis.com

Florian Gross

unread,
Mar 28, 2005, 1:07:06 PM3/28/05
to
Ilias Lazaridis wrote:

>> I've generated this one automatically:
>>
>> http://flgr.0x42.net/class-graph.png
>
> with which tool have you generated this?

Graphviz and a custom Ruby script which uses Ruby's introspection for
finding out the class and module relationships.

Ilias Lazaridis

unread,
Mar 30, 2005, 12:02:02 AM3/30/05
to
Florian Gross wrote:
> Ilias Lazaridis wrote:
>
>>> I've generated this one automatically:
>>>
>>> http://flgr.0x42.net/class-graph.png
>>
>> with which tool have you generated this?
>
> Graphviz

http://www.graphviz.org/

> and a custom Ruby script which uses Ruby's introspection for
> finding out the class and module relationships.

if it is not very long, can you please post it here?

-

btw:

found this ppt-presentation about the object-model (but would prefere an
UML diagramm):

http://rubyforge.org/docman/view.php/251/96/ChrisPine_UROM.ppt

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Mar 30, 2005, 12:26:45 AM3/30/05
to

To save some time, I would like to reverse the process (first the ruby
result, then the general template):

I've reviewed a little the documentation, but find nothing about metadata.

Is there a standard way to apply metadata/annotations to my class
Talker, its Methods, its Attributes?

E.g.:

class Talker

attr_accessor :name # Type = String; Label = Name; Size = 30;
attr_accessor :age # Type = int; Label = Age; Min=1; Max=150;

def sayYourName
end
end

-

"attr_accessor" does not work on class variables (e.g. @@count).

Must I create @@var/getter/setter manually?

.

--
http://lazaridis.com

Martin Ankerl

unread,
Mar 30, 2005, 1:31:50 AM3/30/05
to
> if it is not very long, can you please post it here?

I have a quite similar script here:
http://martinus.geekisp.com/rublog.cgi/Projects/RubyToDot/rubytodot.html

martinus

James Edward Gray II

unread,
Mar 30, 2005, 9:51:17 AM3/30/05
to
On Mar 29, 2005, at 11:29 PM, Ilias Lazaridis wrote:

> I've reviewed a little the documentation, but find nothing about
> metadata.

Probably because it's too general a topic. The word "metadata" changes
meaning by context.

> Is there a standard way to apply metadata/annotations to my class
> Talker, its Methods, its Attributes?
>
> E.g.:
>
> class Talker
>
> attr_accessor :name # Type = String; Label = Name; Size = 30;
> attr_accessor :age # Type = int; Label = Age; Min=1; Max=150;
>
> def sayYourName
> end
> end

Your comment has already hit on one solution. :) There may be many
others, depending on how you intend to use this information...

> -
>
> "attr_accessor" does not work on class variables (e.g. @@count).
>
> Must I create @@var/getter/setter manually?

Not exactly. Here's a trick:

irb(main):001:0> class MyClass
irb(main):002:1> class << self
irb(main):003:2> attr_accessor :test
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> MyClass.test = 501
=> 501
irb(main):007:0> MyClass.test
=> 501

There is a gotcha though:

irb(main):008:0> class MyClass
irb(main):009:1> def test_method
irb(main):010:2> @@test
irb(main):011:2> end
irb(main):012:1> end
=> nil
irb(main):013:0> MyClass.new.test_method
NameError: uninitialized class variable @@test in MyClass
from (irb):10:in `test_method'
from (irb):14
from :0

You can see that this technique does not use @@test.

All of this is just playing around though. If you seriously need to
define class accessors a lot and can't be bothered to type:

def self.test( ) @@test end
def self.test=( value ) @@test = value end

Most editors I've ever seen will allow you to macro that and assign it
to a single keystroke.

My opinion, feel free to completely ignore, is that you've strayed
pretty far from "evaluating Ruby" when you worry about details like
this. We can sit here and show you examples like the above
indefinitely, exploring all corners of the language. There's no
substitute for just learning the language and seeing what it can do for
you though, and this is a poor way to go about that.

James Edward Gray II

Ilias Lazaridis

unread,
Mar 31, 2005, 4:39:51 AM3/31/05
to
James Edward Gray II wrote:
> On Mar 29, 2005, at 11:29 PM, Ilias Lazaridis wrote:
>
>> I've reviewed a little the documentation, but find nothing about
>> metadata.
>
> Probably because it's too general a topic. The word "metadata" changes
> meaning by context.

ok

>> Is there a standard way to apply metadata/annotations to my class
>> Talker, its Methods, its Attributes?
>>
>> E.g.:
>>
>> class Talker
>>
>> attr_accessor :name # Type = String; Label = Name; Size = 30;
>> attr_accessor :age # Type = int; Label = Age; Min=1; Max=150;
>>
>> def sayYourName
>> end
>> end
>
> Your comment has already hit on one solution. :) There may be many
> others, depending on how you intend to use this information...

I extract: Ruby has not standard-mechanism for metadata/annotations.

ok

>> "attr_accessor" does not work on class variables (e.g. @@count).
>>
>> Must I create @@var/getter/setter manually?
>
> Not exactly. Here's a trick:

[...] - (trick's and workarounds)

> Most editors I've ever seen will allow you to macro that and assign it
> to a single keystroke.

I am aware about editors and macros.

-

Where can I find the implementation of "attr_accessor"?

I'm intrested in seeing how much effort it is to write an own
"flex_attr_accessor".

[I will possibly include this in the evaluation template, section
"language extension"]

> My opinion, feel free to completely ignore, is that you've strayed
> pretty far from "evaluating Ruby" when you worry about details like
> this. We can sit here and show you examples like the above
> indefinitely, exploring all corners of the language. There's no
> substitute for just learning the language and seeing what it can do for
> you though, and this is a poor way to go about that.
>
> James Edward Gray II

I've an evaluation template, which I like to apply to several languages.

Ruby looks very nice till now, although I've hit already some limitations:

Ilias Lazaridis

unread,
Mar 31, 2005, 4:40:08 AM3/31/05
to

very nice work.

.

--
http://lazaridis.com

James Edward Gray II

unread,
Mar 31, 2005, 10:57:25 AM3/31/05
to
On Mar 31, 2005, at 3:44 AM, Ilias Lazaridis wrote:

>>> Is there a standard way to apply metadata/annotations to my class
>>> Talker, its Methods, its Attributes?
>>>
>>> E.g.:
>>>
>>> class Talker
>>>
>>> attr_accessor :name # Type = String; Label = Name; Size = 30;
>>> attr_accessor :age # Type = int; Label = Age; Min=1; Max=150;
>>>
>>> def sayYourName
>>> end
>>> end
>> Your comment has already hit on one solution. :) There may be many
>> others, depending on how you intend to use this information...
>
> I extract: Ruby has not standard-mechanism for metadata/annotations.
>
> ok

Correct, but it certainly provides ample tools to build whatever you
need.

This aspect you've just hit on is the very essence of programming, in
my opinion. No language provides everything for every need. The
processes of adapting your chosen language to the problem space is the
craft.

> Where can I find the implementation of "attr_accessor"?
>
> I'm intrested in seeing how much effort it is to write an own
> "flex_attr_accessor".

I'm sure attr_accessor is defined in the Ruby source. Here's my
version of a pure Ruby class accessor:

irb(main):015:0> class Module
irb(main):016:1> def cattr_accessor( *symbols )
irb(main):017:2> symbols.each do |sym|
irb(main):018:3* class_eval "def self.#{sym}( ) @@#{sym} end
irb(main):019:3" def self.#{sym}=( value ) @@#{sym}
= value end"
irb(main):020:3> end
irb(main):021:2> end
irb(main):022:1> end
=> nil
irb(main):023:0> class Accessor
irb(main):024:1> cattr_accessor :one, :two
irb(main):025:1> def self.fetch_one( )
irb(main):026:2> @@one
irb(main):027:2> end
irb(main):028:1> end
=> nil
irb(main):029:0> Accessor.one = "James"
=> "James"
irb(main):030:0> Accessor.two = "Gray"
=> "Gray"
irb(main):031:0> Accessor.one
=> "James"
irb(main):032:0> Accessor.two
=> "Gray"
irb(main):033:0> Accessor.fetch_one
=> "James"

Hope that helps.

James Edward Gray II

Ilias Lazaridis

unread,
Apr 1, 2005, 3:12:33 AM4/1/05
to
James Edward Gray II wrote:
> On Mar 31, 2005, at 3:44 AM, Ilias Lazaridis wrote:
>
>>>> Is there a standard way to apply metadata/annotations to my class
>>>> Talker, its Methods, its Attributes?
[...]

>> I extract: Ruby has not standard-mechanism for metadata/annotations.
>>
>> ok
>
> Correct, but it certainly provides ample tools to build whatever you need.
>
> This aspect you've just hit on is the very essence of programming, in my
> opinion. No language provides everything for every need. The processes
> of adapting your chosen language to the problem space is the craft.

I'm just writing the situation down.

personally to me, language-efficiency is more important than a
standartization [which can btw. limit efficiency, see JAVA].

>> Where can I find the implementation of "attr_accessor"?
>>
>> I'm intrested in seeing how much effort it is to write an own
>> "flex_attr_accessor".
>
> I'm sure attr_accessor is defined in the Ruby source.

ok

> Here's my version of a pure Ruby class accessor:
>
> irb(main):015:0> class Module
> irb(main):016:1> def cattr_accessor( *symbols )

[...]

> Hope that helps.

yes, very nice!

looks like a "macro", written in ruby, made available to a project by
simply including the file.

very nice!

Ilias Lazaridis

unread,
Apr 2, 2005, 3:44:26 AM4/2/05
to
Ilias Lazaridis wrote:
[...]

> I will collect the results and write them down in a document, which will
> compare ruby with other languages.
>
> This document can serve as an flash-start (for people which simply like
> to take a look on ruby).
>
> http://lazaridis.com/case/lang/ruby.html

So, the last question for this part:

how can I add runtime-accessible [meta]data to a ruby function definition?

Any standard to do this?

Or any suggestions?

.

--
http://lazaridis.com

Robert Klemme

unread,
Apr 2, 2005, 5:21:50 AM4/2/05
to

"Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
news:d2lm17$2go$1...@usenet.otenet.gr...

Put a hash into the class with symbol as key and whatever meta data you
need. Add some syntactic sugar and you're done. I'm quite sure someone has
done that already (maybe even on RAA).

Kind regards

robert

Ilias Lazaridis

unread,
Apr 2, 2005, 6:42:58 AM4/2/05
to

?

I don't understand.

def talker

def sayHello
puts "Hello World"
end

def sayYourName
puts @name
end

end

how do I put a "hash" which keeps metadata to each _function_?

> Kind regards
>
> robert
>


--
http://lazaridis.com

Glenn Parker

unread,
Apr 2, 2005, 8:01:03 AM4/2/05
to
Ilias Lazaridis wrote:
>
> I don't understand.

Does anybody else see an analogy to "Blind Man's Bluff" in this thread?

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoil.com/>


Ilias Lazaridis

unread,
Apr 2, 2005, 8:15:28 AM4/2/05
to
Jacob Fugal wrote:
> On Thu, 24 Mar 2005 10:59:50 +0900, Ilias Lazaridis <il...@lazaridis.com> wrote:
[...]

>>"#" is used as a comment marker _and_ partly within code.
>>
>>Can I use another comment marker?
>
> No. To my knowledge there is only the one comment syntax in ruby.

ok

>>Can I write "puts "#{thisMethodName}: Hello World"" in an different
>>manner, without the use of "#"?
>
> Sure. #{thisMethodName} in a string literal simply calls .to_s on the
> enclosed expression and inserts it at the designated location. So we
> can pull that out such:
>
> puts thisMethodName.to_s + ": Hello World"

ok.

I like this contruct more:

"puts "#{thisMethodName}: Hello World"

but the usage of "#" is missleading (comment marker)

> The + operator performs concatenation when its arguments are strings.
>
> Jacob Fugal

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 2, 2005, 8:59:49 AM4/2/05
to
Tom Copeland wrote:
> On Wed, 2005-03-23 at 10:39 +0900, Ilias Lazaridis wrote:
>
>>Can one suggest me the simplest possible installation (one-click)?
>>
>>One for Windows and one for Linux (if possible similar in content)?
>
>
> Installer for Windows is here:
>
> http://rubyforge.org/frs/?group_id=167

I was surprised from the quality of the distribution.

ok

how does a mac-user install ruby?

> Yours,
>
> Tom

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 2, 2005, 9:02:31 AM4/2/05
to
Ilias Lazaridis wrote:
> [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework
> http://groups-beta.google.com/group/comp.lang.ruby/msg/0fb8b0824d4fbaec
>
> -
>
> The above thread showed finally the need to split the evaluation down
> into smaller chunks.
>
> Here is a simple evaluation template (first part) which can be applied
> to the Ruby language:
>
> http://lazaridis.com/case/lang/index.html
>
> If you like, please post the most elegant solutions (either to sections
> or to the whole document).
>
> I will collect the results and write them down in a document, which will
> compare ruby with other languages.
>
> This document can serve as an flash-start (for people which simply like
> to take a look on ruby).
>
> http://lazaridis.com/case/lang/ruby.html

I hope you like the results so far.

I need to fill in the interactive session, to close this thread:

http://lazaridis.com/case/lang/index.html#run_interactive

http://lazaridis.com/case/lang/ruby.html#run_interactive

.

--
http://lazaridis.com

Luc Heinrich

unread,
Apr 2, 2005, 11:21:36 AM4/2/05
to
Ilias Lazaridis <il...@lazaridis.com> wrote:

> how does a mac-user install ruby?

A mac user does not install Ruby, because Mac OS X already has it
pre-installed. Macs are better, everybody knows this... :>

However, if a mac user wants the latest and greatest, he usually
downloads the source tarball, go to the terminal and type:

% ./configure
% make
% sudo make install

Boom, done (ok, you might want to make sure your $PATH gets you to the
new one instead of the default one, but that's pretty much it).

--
Luc Heinrich - luc...@mac.com

Ilias Lazaridis

unread,
Apr 2, 2005, 11:40:31 AM4/2/05
to
Luc Heinrich wrote:
> Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>how does a mac-user install ruby?
>
> A mac user does not install Ruby, because Mac OS X already has it
> pre-installed.

intresting.

> Macs are better, everybody knows this... :>
>
> However, if a mac user wants the latest and greatest, he usually
> downloads the source tarball, go to the terminal and type:
>
> % ./configure
> % make
> % sudo make install
>
> Boom, done (ok, you might want to make sure your $PATH gets you to the
> new one instead of the default one, but that's pretty much it).

I would expect this update sequence (from a better System):

macup ruby latest_release

-

ok, I extract that I don't have to include download instructions for MAC
users.

.

--
http://lazaridis.com

Robert Klemme

unread,
Apr 2, 2005, 12:45:34 PM4/2/05
to

"Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
news:d2m0g0$j8q$1...@usenet.otenet.gr...

class Module
def meta() @meta ||= {} end
end

class Foo
def bar() end
meta[:bar] = "bar_meta"
end

>> puts Foo.meta[:bar]
bar_meta
=> nil

Regards

robert

Ilias Lazaridis

unread,
Apr 3, 2005, 7:37:41 AM4/3/05
to
Robert Klemme wrote:
[...]

>>>> So, the last question for this part:
>>>>
>>>> how can I add runtime-accessible [meta]data to a ruby function
>>>> definition?

[...]

>> I don't understand.
>>
>> def talker
>>
>> def sayHello
>> puts "Hello World"
>> end
>>
>> def sayYourName
>> puts @name
>> end
>>
>> end
>>
>> how do I put a "hash" which keeps metadata to each _function_?
>
> class Module
> def meta() @meta ||= {} end
> end
>
> class Foo
> def bar() end
> meta[:bar] = "bar_meta"
> end

[...]

the above is essentially "class metadata".

but it gives me the basic idea:

class Object


def meta() @meta ||= {} end
end

talker.sayYourName.meta[:author] = "it's just me"
puts talker.sayYourName.meta[:author]
=> it's just me

[i like this language *very* much]

-

But to understand this fully, can someone please decrypt this:

def meta()
@meta ||= {}
end

.

--
http://lazaridis.com

Anders Engström

unread,
Apr 3, 2005, 8:11:15 AM4/3/05
to
On Sun, Apr 03, 2005 at 08:39:42PM +0900, Ilias Lazaridis wrote:
[snipp]

> But to understand this fully, can someone please decrypt this:
>
> def meta()
> @meta ||= {}
> end
>

That's lazy initialization of the @meta variable. Another (and more
verbose) way to write it would be:

def meta()
unless @meta #If not defined, set the value
@meta = {}
end
@meta # Return Meta
end

"@meta ||= {}" evaluates to "@meta = @meta || {}" and since the returned
value from a method is the last evaluated expression "@meta ||= {}"
works.

//Anders

--
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Anders Engström aeng...@gnejs.net
http://www.gnejs.net PGP-Key: ED010E7F
[Your mind is like an umbrella. It doesn't work unless you open it.]


Robert Klemme

unread,
Apr 3, 2005, 8:14:18 AM4/3/05
to

"Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
news:d2oki2$4m$1...@usenet.otenet.gr...

If @meta is something false (i.e. nil or false) then the expression on the
right hand side is evaluated and the result is assigned to @meta. It's
short for any of these

@meta = {} unless @meta
@meta || (@meta = {})
@meta or @meta = {}

{} creates a hash (synonym for Hash.new, but you can also put values there
like {"foo"=>"bar"}).

HTH

robert

Ilias Lazaridis

unread,
Apr 3, 2005, 8:50:54 AM4/3/05
to
Robert Klemme wrote:
[...]

>> [i like this language *very* much]
>>
>> -
>>
>> But to understand this fully, can someone please decrypt this:
>>
>> def meta()
>> @meta ||= {}
>> end
>
> If @meta is something false (i.e. nil or false) then the expression on
> the right hand side is evaluated and the result is assigned to @meta.
> It's short for any of these
>
> @meta = {} unless @meta
> @meta || (@meta = {})
> @meta or @meta = {}
>
> {} creates a hash (synonym for Hash.new, but you can also put values
> there like {"foo"=>"bar"}).

ok

you answer together with the other answer => i got it:

def meta() # use of "()" is optional
unless @meta # if @meta == nil ("unless" is the same as "if not")
@meta = {} # creates a new hash
end
@meta # returns the hash

Csaba Henk

unread,
Apr 3, 2005, 8:51:29 AM4/3/05
to
On 2005-04-03, Ilias Lazaridis <il...@lazaridis.com> wrote:
>>> def talker
>>>
>>> def sayHello
>>> puts "Hello World"
>>> end
>>>
>>> def sayYourName
>>> puts @name
>>> end
>>>
>>> end

[snip]

> but it gives me the basic idea:
>
> class Object
> def meta() @meta ||= {} end
> end
>
> talker.sayYourName.meta[:author] = "it's just me"
> puts talker.sayYourName.meta[:author]
>=> it's just me

If you want metadata for the _function_, then it's not exactly the way
to go.

The sayYourName method, as defined above, is a side-effecting one,
writes out @name, then returns nil, which is a unique object, without
any reference to talker. That is, it's not a possible carrier of
metainformation.

What seems to be feasible is implementing one of the following
behaviours:

talker.meta[:sayYourName][:author] # => "it's just me"

or

talker.method(:sayYourName).meta[:author] # => "it's just me"

or if you are on steroids, maybe

talker.meta[:sayYourName].author

or

talker.method(:sayYourName).meta.author

(FYI, Object#method takes a symbol or a string, and returns the method
named thusly as an obejct.)

Csaba

Ilias Lazaridis

unread,
Apr 3, 2005, 9:02:23 AM4/3/05
to
Anders Engström wrote:
> On Sun, Apr 03, 2005 at 08:39:42PM +0900, Ilias Lazaridis wrote:
> [snipp]
>
>>But to understand this fully, can someone please decrypt this:
>>
>> def meta()
>> @meta ||= {}
>> end
>
> That's lazy initialization of the @meta variable. Another (and more
> verbose) way to write it would be:
>
> def meta()
> unless @meta #If not defined, set the value
> @meta = {}
> end
> @meta # Return Meta
> end

def meta() # use of "()" is optional
unless @meta # if @meta == nil (unless = if not)


@meta = {} # creates a new hash
end

@meta # returns the (existing or new) hash
end

> "@meta ||= {}" evaluates to "@meta = @meta || {}" and since the returned

"||=" similar to "+="

"||" means: if left operand is nil, pick right operand.

> value from a method is the last evaluated expression "@meta ||= {}"
> works.

ok, got it!

[will update the document soon - and hopefully can soon take the next round]

> //Anders

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 3, 2005, 9:44:21 AM4/3/05
to
Ilias Lazaridis wrote:
> Ilias Lazaridis wrote:
[...]

>> This document can serve as an flash-start (for people which simply
>> like to take a look on ruby).
>>
>> http://lazaridis.com/case/lang/ruby.html
>
> I hope you like the results so far.
>
> I need to fill in the interactive session, to close this thread:
>
> http://lazaridis.com/case/lang/index.html#run_interactive
>
> http://lazaridis.com/case/lang/ruby.html#run_interactive

I've tried this:

open command window
change to project directory
cmd: irb
within irb
cmd: require 'talker'

talker is created, produces output.

but: the "talker" instance which was created during read in (of
talker.rb) has died.

why?

how do i read-in files, which produce instances, which 'survive'?

and: how do I delete an instance? [tried: del, delete, kill, rm, free]

.

--
http://lazaridis.com

Saynatkari

unread,
Apr 3, 2005, 10:12:35 AM4/3/05
to

Le 3/4/2005, "Ilias Lazaridis" <il...@lazaridis.com> a écrit:

>Ilias Lazaridis wrote:
>> Ilias Lazaridis wrote:
>[...]
>
>>> This document can serve as an flash-start (for people which simply
>>> like to take a look on ruby).
>>>
>>> http://lazaridis.com/case/lang/ruby.html
>>
>> I hope you like the results so far.
>>
>> I need to fill in the interactive session, to close this thread:
>>
>> http://lazaridis.com/case/lang/index.html#run_interactive
>>
>> http://lazaridis.com/case/lang/ruby.html#run_interactive
>
>I've tried this:
>
>open command window
>change to project directory
>cmd: irb
>within irb
>cmd: require 'talker'
>
>talker is created, produces output.
>
>but: the "talker" instance which was created during read in (of
>talker.rb) has died.
>
>why?

Local variables evaluated during a require() are not accessible
from outside the file; you may consider this such that the file
is the scope within which the variable is defined, just like in
a method body.

>how do i read-in files, which produce instances, which 'survive'?

Global variables (although this practice would be discouraged),
which are identified by a $-prefix, e.g. $global = 'something'.
Come to think of it, constants may also be accessible.

Normally one will have either an accessor method of some sort
or simply provide the means of _creating_ an instance.

>and: how do I delete an instance? [tried: del, delete, kill, rm, free]

One cannot explicitly delete an instance. It will be 'deleted'
(marked for garbage collection) once it is without references.

E

No-one expects the Solaris POSIX implementation!

Ilias Lazaridis

unread,
Apr 3, 2005, 11:26:47 AM4/3/05
to
Saynatkari wrote:
> Le 3/4/2005, "Ilias Lazaridis" <il...@lazaridis.com> a écrit:
>>Ilias Lazaridis wrote:
[...]

>>>I need to fill in the interactive session, to close this thread:
>>>
>>>http://lazaridis.com/case/lang/index.html#run_interactive
>>>
>>>http://lazaridis.com/case/lang/ruby.html#run_interactive
>>
>>I've tried this:
>>
>>open command window
>>change to project directory
>>cmd: irb
>>within irb
>>cmd: require 'talker'
>>
>>talker is created, produces output.
>>
>>but: the "talker" instance which was created during read in (of
>>talker.rb) has died.
>>
>>why?
>
> Local variables evaluated during a require() are not accessible
> from outside the file; you may consider this such that the file
> is the scope within which the variable is defined, just like in
> a method body.

I understand.

instead of 'require', can I use another command, like e.g. "expand".

>>how do i read-in files, which produce instances, which 'survive'?
>
> Global variables (although this practice would be discouraged),
> which are identified by a $-prefix, e.g. $global = 'something'.
> Come to think of it, constants may also be accessible.

ok

> Normally one will have either an accessor method of some sort
> or simply provide the means of _creating_ an instance.
>
>>and: how do I delete an instance? [tried: del, delete, kill, rm, free]
>
> One cannot explicitly delete an instance. It will be 'deleted'
> (marked for garbage collection) once it is without references.

how can i reverse the process?

I like to kill the object, thus the destructor is called.

the references will point to nil.

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 3, 2005, 11:30:30 AM4/3/05
to
[...] - (several other suggestions)

I like the extracted construct - and it works in practice.

Thus I'm covered in this point.

Thank you for your suggestions.

.

--
http://lazaridis.com

Saynatkari

unread,
Apr 3, 2005, 11:58:04 AM4/3/05
to

Le 3/4/2005, "Ilias Lazaridis" <il...@lazaridis.com> a écrit:

Just to make sure there is no confusion:

talker.sayYourName.meta[:author] = "it's just me"

sayYourName, when evaluated, returns nil. Therefore,
your meta structure is actually in the instance of
NilClass, not Talker. You should be able to test it
by trying nil.meta[:author] after you execute the
above code.

You would want to follow the original example,
or do something like this (you can elaborate
on the documentation notation):

class Object
def doc(str)
@doc_data ||= {}
# caller[1] will be the method name doc() was called from.
@doc_data[caller[1]] = str
end
end

class SomeClass
# Some method
def some_method
doc "This method does something."
# ...
end
end

>http://lazaridis.com

Ilias Lazaridis

unread,
Apr 3, 2005, 1:21:43 PM4/3/05
to
Csaba Henk wrote:
> On 2005-04-03, Ilias Lazaridis <il...@lazaridis.com> wrote:
[...]

>>but it gives me the basic idea:
>>
>>class Object
>> def meta() @meta ||= {} end
>>end
>>
>>talker.sayYourName.meta[:author] = "it's just me"
>>puts talker.sayYourName.meta[:author]
>>=> it's just me
>
> If you want metadata for the _function_, then it's not exactly the way
> to go.
>
> The sayYourName method, as defined above, is a side-effecting one,
> writes out @name, then returns nil, which is a unique object, without
> any reference to talker. That is, it's not a possible carrier of
> metainformation.

[...]

after the other message and some more tests I understood you objections
and suggestion.

I sincerly apologize for rejecting them without further and deeper
evaluating them, trusting a little bit your experience.

I will continue tomorrow, as I've a blackout now.

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 3, 2005, 1:45:31 PM4/3/05
to
Saynatkari wrote:
> Le 3/4/2005, "Ilias Lazaridis" <il...@lazaridis.com> a écrit:
>>Csaba Henk wrote:
>>>On 2005-04-03, Ilias Lazaridis <il...@lazaridis.com> wrote:
[...]

>>>>but it gives me the basic idea:
>>>>
>>>>class Object
>>>> def meta() @meta ||= {} end
>>>>end
>>>>
>>>>talker.sayYourName.meta[:author] = "it's just me"
>>>>puts talker.sayYourName.meta[:author]
>>>>=> it's just me
>>>
>>>If you want metadata for the _function_, then it's not exactly the way
>>>to go.
>>>
>>>The sayYourName method, as defined above, is a side-effecting one,
>>>writes out @name, then returns nil, which is a unique object, without
>>>any reference to talker. That is, it's not a possible carrier of
>>>metainformation.

[...]

>>I like the extracted construct - and it works in practice.

[...]

> Just to make sure there is no confusion:
>
> talker.sayYourName.meta[:author] = "it's just me"
>
> sayYourName, when evaluated, returns nil.

This behaviour seems non logical.

talker.sayYourName.meta

talker_object->sayYourName_object->meta_object
Class object Method object Hash object

The sayYourName Method Object is not executed, it's just a part of the
nested datastructure.

> Therefore,
> your meta structure is actually in the instance of
> NilClass, not Talker. You should be able to test it
> by trying nil.meta[:author] after you execute the
> above code.

yes, i've verified this (with the quick test it seemed to work).

I've understood the example you give below.

But I like to have the metadata directly on my function.

And this without further indirection (at least not visual).

> You would want to follow the original example,
> or do something like this (you can elaborate
> on the documentation notation):
>
> class Object
> def doc(str)
> @doc_data ||= {}
> # caller[1] will be the method name doc() was called from.
> @doc_data[caller[1]] = str
> end
> end
>
> class SomeClass
> # Some method
> def some_method
> doc "This method does something."
> # ...
> end
> end

.

--
http://lazaridis.com

Saynatkari

unread,
Apr 3, 2005, 2:13:28 PM4/3/05
to

You are not accessing the method, you are _calling_ the method.
As mentioned earlier, talker.method(:sayYourName).meta would
work.

>> Therefore,
>> your meta structure is actually in the instance of
>> NilClass, not Talker. You should be able to test it
>> by trying nil.meta[:author] after you execute the
>> above code.
>
>yes, i've verified this (with the quick test it seemed to work).
>
>I've understood the example you give below.
>
>But I like to have the metadata directly on my function.
>
>And this without further indirection (at least not visual).

This would require changes to the parser, so I do not see
it happening at least before 2.0. On the other hand, zenspider
promised on IRC to pay $50.00 to anyone who will patch the parser
to read comments into the AST, so...

In the interim, I think a fairly robust solution would be to
just write normal offline rdoc documentation for the source
code and then write some sort of a bridge that reads the
metadata in from the rdoc and either creates a .rb file that
can be included in one's program or directly extracts the
information from rdoc at runtime.

>> You would want to follow the original example,
>> or do something like this (you can elaborate
>> on the documentation notation):
>>
>> class Object
>> def doc(str)
>> @doc_data ||= {}
>> # caller[1] will be the method name doc() was called from.
>> @doc_data[caller[1]] = str
>> end
>> end
>>
>> class SomeClass
>> # Some method
>> def some_method
>> doc "This method does something."
>> # ...
>> end
>> end
>

>..
>
>--

Robert Klemme

unread,
Apr 4, 2005, 2:10:09 AM4/4/05
to

"Saynatkari" <rub...@magical-cat.org> schrieb im Newsbeitrag
news:8yz1QGr1.11125520...@bidwell.textdrive.com...

No, it doesn't. Method instances are not suited to carrying meta data:

>> class Foo; def bar() end end
=> nil
>> Foo.new.method(:bar).meta[:test]="I'm here"
=> "I'm here"
>> f=Foo.new
=> #<Foo:0x10184008>
>> f.method(:bar).meta[:test]="I'm here"
=> "I'm here"
>> f.method(:bar).meta[:test]
=> nil

The reason is that Method instances are created on each request:

>> f.method(:bar).__id__
=> 134967116
>> f.method(:bar).__id__
=> 134950544
>> f.method(:bar).__id__
=> 134664456
>> f.method(:bar).__id__
=> 134636916

You have to stick to the class or object as point where meta data is stored.
If you want to store a hash per method you can do

class Object
def meta() @meta ||= Hash.new{|h,k| h[k]={}} end
end

>> f=Foo.new
=> #<Foo:0x101acf88>
>> f.meta[:bar][:info]="test"
=> "test"
>> f.meta[:bar]
=> {:info=>"test"}
>> f.meta[:bar][:info]
=> "test"

Kind regards

robert

Csaba Henk

unread,
Apr 4, 2005, 4:40:57 AM4/4/05
to
On 2005-04-04, Robert Klemme <bob....@gmx.net> wrote:
> "Saynatkari" <rub...@magical-cat.org> schrieb im Newsbeitrag
>> You are not accessing the method, you are _calling_ the method.
>> As mentioned earlier, talker.method(:sayYourName).meta would
>> work.
>
> No, it doesn't. Method instances are not suited to carrying meta data:

[snip]

> The reason is that Method instances are created on each request:

Hmm, that's interesting. Good to know of it. So then methods are not
objects per se, they just can be objectified.

Then really talker.meta[:sayYourName][:author] is the way to go. Of
course, if the metadata is not intended/needed to be instance-specific,
then it's better to be appended to the class.

Csaba

Ilias Lazaridis

unread,
Apr 4, 2005, 7:42:26 AM4/4/05
to

Thank's to all replies.

I've understood now the problem.

-

The Ruby Object Model does not contain reflective MetaClasses, which
would enable to apply metadata even to methods.

-

I would like to know how a class which i've defined is represented in
memory, and how I can access it.

-

A Visual representation of the Relevant Ruby Object Model (e.g. with
UML) would be very helpfull to understand this immediately.

.

--
http://lazaridis.com

Robert Klemme

unread,
Apr 4, 2005, 8:09:33 AM4/4/05
to

"Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
news:d2r96v$c9c$1...@usenet.otenet.gr...

> Csaba Henk wrote:
> > On 2005-04-04, Robert Klemme <bob....@gmx.net> wrote:
> >
> >>"Saynatkari" <rub...@magical-cat.org> schrieb im Newsbeitrag
> >>
> >>>You are not accessing the method, you are _calling_ the method.
> >>>As mentioned earlier, talker.method(:sayYourName).meta would
> >>>work.
> >>
> >>No, it doesn't. Method instances are not suited to carrying meta
data:
> >
> > [snip]
> >
> >>The reason is that Method instances are created on each request:
> >
> > Hmm, that's interesting. Good to know of it. So then methods are not
> > objects per se, they just can be objectified.
> >
> > Then really talker.meta[:sayYourName][:author] is the way to go. Of
> > course, if the metadata is not intended/needed to be
instance-specific,
> > then it's better to be appended to the class.
> >
> > Csaba
>
> Thank's to all replies.
>
> I've understood now the problem.
>
> -
>
> The Ruby Object Model does not contain reflective MetaClasses, which
> would enable to apply metadata even to methods.

I'm not sure what exactly you mean by this. You can indeed access classes
in Ruby. So I'd say there *are* MetaClasses. It's just that there is no
persistent representation of methods which you could augment with
additional data.

> I would like to know how a class which i've defined is represented in
> memory, and how I can access it.

You just access them like any object, only that class instances are
assigned to constants:

>> class Foo;end
=> nil
>> Foo.instance_variables
=> []
>> class Foo
>> class <<self
>> attr_accessor :bar
>> end
>> end
=> nil
>> Foo.bar = "test"
=> "test"
>> Foo.bar
=> "test"
>> Foo.instance_variables
=> ["@bar"]
>> o=Foo
=> Foo
>> o.new
=> #<Foo:0x10185728>

> A Visual representation of the Relevant Ruby Object Model (e.g. with
> UML) would be very helpfull to understand this immediately.

I don't know whether such thing exists, but the concept is usually easy
grasped IMHO. Try to play a bit with classes in IRB - that helped me a
lot. Note especially methods #class, #ancestors and #superclass.

Kind regards

robert

James Edward Gray II

unread,
Apr 4, 2005, 9:18:53 AM4/4/05
to
On Apr 4, 2005, at 3:54 AM, Csaba Henk wrote:

> Then really talker.meta[:sayYourName][:author] is the way to go. Of
> course, if the metadata is not intended/needed to be instance-specific,
> then it's better to be appended to the class.

If the metadata has anything to do with method execution, say tracking
running time for example, you could implement accessors in Object and
call them in the method itself. From that call, caller() can be used
to index into some global hash that tracks the data.

Just thinking out loud here...

James Edward Gray II

Csaba Henk

unread,
Apr 4, 2005, 9:14:39 AM4/4/05
to
On 2005-04-04, Ilias Lazaridis <il...@lazaridis.com> wrote:
> A Visual representation of the Relevant Ruby Object Model (e.g. with
> UML) would be very helpfull to understand this immediately.

You can find something like this at
http://www.ruby-doc.org/core/classes/Class.html -- though not UML just
simple ascii art.

You might as well enjoy "A Little Ruby, A Lot of Objects" by Brian
Marick (http://www.visibleworkings.com/little-ruby/). In the 3rd chapter
a visualization of the Ruby object model is worked out in a
step-by-step, deductive way (which is the methodology of the whole
work).

Csaba

James Edward Gray II

unread,
Apr 4, 2005, 9:26:19 AM4/4/05
to
On Apr 4, 2005, at 6:44 AM, Ilias Lazaridis wrote:

> A Visual representation of the Relevant Ruby Object Model (e.g. with
> UML) would be very helpfull to understand this immediately.

There are nice diagrams of this relationship in Programming Ruby
(Chapter 24: Objects and Classes).

James Edward Gray II

George Moschovitis

unread,
Apr 4, 2005, 9:39:03 AM4/4/05
to
> There are nice diagrams of this relationship in Programming Ruby
> (Chapter 24: Objects and Classes).

or you can just use ri:

ri Class

generates an ASCII version of the diagrams.

George.

--
http://nitro.rubyforge.org

Ilias Lazaridis

unread,
Apr 4, 2005, 9:54:02 AM4/4/05
to
Robert Klemme wrote:
> "Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
> news:d2r96v$c9c$1...@usenet.otenet.gr...
[...]

>>I've understood now the problem.
>>
>>-
>>
>>The Ruby Object Model does not contain reflective MetaClasses, which
>>would enable to apply metadata even to methods.
>
> I'm not sure what exactly you mean by this. You can indeed access classes
> in Ruby. So I'd say there *are* MetaClasses. It's just that there is no
> persistent representation of methods which you could augment with
> additional data.

[...] - (some examples)

ok, there are metaclasses, which are not fully(!) reflective (as already
showcased due to the missing possiility to recreate the class-definition).

[E.g. Smalltalks object model is fully reflective (classes are instances
of metaclasses).]

>>A Visual representation of the Relevant Ruby Object Model (e.g. with
>>UML) would be very helpfull to understand this immediately.
>
> I don't know whether such thing exists, but the concept is usually easy
> grasped IMHO. Try to play a bit with classes in IRB - that helped me a
> lot. Note especially methods #class, #ancestors and #superclass.

[I must close this thread here - I've dived already too deep]

One could possibly ask in the developers list.

This documentation should be in a central place on ruby-lang.org.

An language-object-model should be document clearly.

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 4, 2005, 10:01:19 AM4/4/05
to
George Moschovitis wrote:
>> There are nice diagrams of this relationship in Programming Ruby
>> (Chapter 24: Objects and Classes).

Is this book available online?

> or you can just use ri:
>
> ri Class
>
> generates an ASCII version of the diagrams.

where do i use it?

> George.
>
> --
> http://nitro.rubyforge.org


--
http://lazaridis.com

Csaba Henk

unread,
Apr 4, 2005, 9:51:20 AM4/4/05
to
On 2005-04-04, Ilias Lazaridis <il...@lazaridis.com> wrote:
> The Ruby Object Model does not contain reflective MetaClasses, which
> would enable to apply metadata even to methods.

You can attach metadata to a certain method object, it's just not what
you will want. Why? Because you refer to a method via the object to which
it belongs, and this always give you a fresh objectification of the
method, as we have discussed.

But. If you stick to refer to methods via their carrier objects (which
you seem to do, and which seems to make sense), then why can't you just
use the object itself as the basic reference point, without further
considerations? Why would be talker.meta[:sayYourName] worse (in any
sense) than what the (disfunctional) talker.method(:sayYourName) could
be?

I mean, the certain object gives the namespace via which you can access
the method as an object. Then why not use the same namespace for storing
the metainformation of the method (without any bitterness)?

Even better, you could make the class or module carry the
metainformation, to which the method belongs as an instance method (each
method is registered as an instance method of some class or module --
singleton methods of an object are instance methods of the metaclass of
the object [accessible as in

class << "a"; self; end

and it is a permanent object, unlike methods]).

This has the advantage that method objects then determine their proposed
metainformation, as they hold a reference to the class/module to which
they belong as an instance method. Alas, in present ruby you can't get
this information explicitly, and now if you say it's a flaw in Ruby, I'd
say I agree (although one which doesn't seem to cause great problems).

For example,

[1].method(:at).inspect

gives the string "#<Method: Array#at>", but there is no method of the
method object [1].method(:at) which would give you Array, the class. In
this particular case, as a clumsy workaround, you could parse out Array
from the above string, but this won't work if the method in question
belongs to an anonymous class (like objects' metaclasses).

Huh, I hope it's not too messy.

Csaba

Robert Klemme

unread,
Apr 4, 2005, 9:59:19 AM4/4/05
to

"Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
news:d2rgtn$gaf$1...@usenet.otenet.gr...

> Robert Klemme wrote:
> > "Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
> > news:d2r96v$c9c$1...@usenet.otenet.gr...
> [...]
>
> >>I've understood now the problem.
> >>
> >>-
> >>
> >>The Ruby Object Model does not contain reflective MetaClasses, which
> >>would enable to apply metadata even to methods.
> >
> > I'm not sure what exactly you mean by this. You can indeed access
classes
> > in Ruby. So I'd say there *are* MetaClasses. It's just that there is
no
> > persistent representation of methods which you could augment with
> > additional data.
> [...] - (some examples)
>
> ok, there are metaclasses, which are not fully(!) reflective (as already
> showcased due to the missing possiility to recreate the
class-definition).
>
> [E.g. Smalltalks object model is fully reflective (classes are instances
> of metaclasses).]

If that's the criterion I'd say that is indeed fully reflective:

>> class Foo;end
=> nil

>> Foo.class
=> Class
>> Foo.kind_of? Class
=> true
>> Foo.kind_of? Module
=> true
>> Class === Foo
=> true
>> Module === Foo
=> true
>> Foo.class.ancestors
=> [Class, Module, Object, Kernel]

In spite of that you cannot recreate a class definition because you cannot
extract method bodies from the meta data. All you get is method names via
#instance_methods and their arity. Does Smalltalk provide more?

Cheers

robert

Ilias Lazaridis

unread,
Apr 4, 2005, 10:35:44 AM4/4/05
to
[...]

>>>>The Ruby Object Model does not contain reflective MetaClasses, which
>>>>would enable to apply metadata even to methods.
[...]

>>ok, there are metaclasses, which are not fully(!) reflective (as already
>>showcased due to the missing possiility to recreate the class-definition).
>
>>[E.g. Smalltalks object model is fully reflective (classes are instances
>>of metaclasses).]
>
> If that's the criterion I'd say that is indeed fully reflective:

[...] - (some examples)

if ruby _is_ fully reflective, than please provide the code for "class
definition recreation"

http://lazaridis.com/case/lang/ruby.html#sayYourClassDefinition

> => [Class, Module, Object, Kernel]
>
> In spite of that you cannot recreate a class definition because you cannot
> extract method bodies from the meta data. All you get is method names via
> #instance_methods and their arity. Does Smalltalk provide more?

yes.

I've quickly found this here, which expresses the relevant points:

http://www.zenspider.com/Languages/Smalltalk/VsJava.html

[but please let's close this subthread, as I move out of topic and out
of time.]

.

--
http://lazaridis.com

James Edward Gray II

unread,
Apr 4, 2005, 10:39:09 AM4/4/05
to
On Apr 4, 2005, at 9:04 AM, Ilias Lazaridis wrote:

> George Moschovitis wrote:
>>> There are nice diagrams of this relationship in Programming Ruby
>>> (Chapter 24: Objects and Classes).
>
> Is this book available online?

The first edition of the book (now in its second edition) is available
online, but the figures aren't in it. They are what you are after.

>> or you can just use ri:
>> ri Class
>> generates an ASCII version of the diagrams.
>
> where do i use it?

ri should be installed with Ruby. The documentation may or may not
have been, depending on how you installed Ruby. If it is installed,
typing "ri Class" at the command-line will fetch the document.

I'll inline the document George mentioned below, for reference, but I
don't personally feel it's as helpful as the figures in Programming
Ruby.

James Edward Gray II

-------------------------------------------------- Class: Class < Module
Classes in Ruby are first-class objects---each is an instance of
class Class.

When a new class is created (typically using class Name ... end),
an object of type Class is created and assigned to a global
constant (Name in this case). When Name.new is called to create a
new object, the new method in Class is run by default. This can be
demonstrated by overriding new in Class:

class Class
alias oldNew new
def new(*args)
print "Creating a new ", self.name, "\n"
oldNew(*args)
end
end

class Name
end

n = Name.new

produces:

Creating a new Name

Classes, modules, and objects are interrelated. In the diagram
that follows, the arrows represent inheritance, and the
parentheses meta-classes. All metaclasses are instances of the
class `Class'.

+------------------+
| |
Object---->(Object) |
^ ^ ^ ^ |
| | | | |
| | +-----+ +---------+ |
| | | | |
| +-----------+ | |
| | | | |
+------+ | Module--->(Module) |
| | ^ ^ |
OtherClass-->(OtherClass) | | |
| | |
Class---->(Class) |
^ |
| |
+----------------+

------------------------------------------------------------------------

Class methods:
new

Instance methods:
allocate, inherited, initialize_copy, new, superclass

Ilias Lazaridis

unread,
Apr 4, 2005, 10:45:50 AM4/4/05
to
Csaba Henk wrote:
> On 2005-04-04, Ilias Lazaridis <il...@lazaridis.com> wrote:
>
>>A Visual representation of the Relevant Ruby Object Model (e.g. with
>>UML) would be very helpfull to understand this immediately.
>
> You can find something like this at
> http://www.ruby-doc.org/core/classes/Class.html -- though not UML just
> simple ascii art.

ok, but this is too less information

(but it shows the involved classes)

> You might as well enjoy "A Little Ruby, A Lot of Objects" by Brian
> Marick (http://www.visibleworkings.com/little-ruby/). In the 3rd chapter
> a visualization of the Ruby object model is worked out in a
> step-by-step, deductive way (which is the methodology of the whole
> work).

and this is too much information for me.

Possibly I will create an UML diagramm.

.

--
http://lazaridis.com

Robert Klemme

unread,
Apr 4, 2005, 10:48:23 AM4/4/05
to

"Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
news:d2rjbt$qs3$1...@usenet.otenet.gr...

The major difference I can see at the moment is that you seem to get
access to the method body in Smalltalk. That's nice. Though I have to
admit that I never missed this feature...

> [but please let's close this subthread, as I move out of topic and out
> of time.]

:-) I think I get the difference now. Thanks.

Kind regards

robert

Ilias Lazaridis

unread,
Apr 4, 2005, 10:55:34 AM4/4/05
to
Robert Klemme wrote:
> "Ilias Lazaridis" <il...@lazaridis.com> schrieb im Newsbeitrag
> news:d2rjbt$qs3$1...@usenet.otenet.gr...
>>[...]
>>
>>>>>>The Ruby Object Model does not contain reflective MetaClasses, which
>>>>>>would enable to apply metadata even to methods.
[...]

>>if ruby _is_ fully reflective, than please provide the code for "class
>>definition recreation"
>>
>>http://lazaridis.com/case/lang/ruby.html#sayYourClassDefinition
[...]

[...]


>>>#instance_methods and their arity. Does Smalltalk provide more?
>>
>>yes.
>>
>>I've quickly found this here, which expresses the relevant points:
>>
>>http://www.zenspider.com/Languages/Smalltalk/VsJava.html
>
> The major difference I can see at the moment is that you seem to get
> access to the method body in Smalltalk. That's nice. Though I have to
> admit that I never missed this feature...

ok

>>[but please let's close this subthread, as I move out of topic and out
>>of time.]
>
> :-) I think I get the difference now. Thanks.

you are welcome.

Thank you for the conversation.

.

--
http://lazaridis.com

Ilias Lazaridis

unread,
Apr 4, 2005, 11:02:18 AM4/4/05
to
James Edward Gray II wrote:
> On Apr 4, 2005, at 9:04 AM, Ilias Lazaridis wrote:
>
>> George Moschovitis wrote:
>>
>>>> There are nice diagrams of this relationship in Programming Ruby
>>>> (Chapter 24: Objects and Classes).
>>
>> Is this book available online?
>
> The first edition of the book (now in its second edition) is available
> online, but the figures aren't in it. They are what you are after.

sad.

>>> or you can just use ri:
>>> ri Class
>>> generates an ASCII version of the diagrams.
>>
>> where do i use it?
>
> ri should be installed with Ruby. The documentation may or may not have
> been, depending on how you installed Ruby. If it is installed, typing
> "ri Class" at the command-line will fetch the document.

ok, it works.

>
> I'll inline the document George mentioned below, for reference, but I
> don't personally feel it's as helpful as the figures in Programming Ruby.

[...]

he refered most possibly to this:

(this is what I would need as a UML diagramm)

> Classes, modules, and objects are interrelated. In the diagram
> that follows, the arrows represent inheritance, and the
> parentheses meta-classes. All metaclasses are instances of the
> class `Class'.
>
> +------------------+
> | |
> Object---->(Object) |
> ^ ^ ^ ^ |
> | | | | |
> | | +-----+ +---------+ |
> | | | | |
> | +-----------+ | |
> | | | | |
> +------+ | Module--->(Module) |
> | | ^ ^ |
> OtherClass-->(OtherClass) | | |
> | | |
> Class---->(Class) |
> ^ |
> | |
> +----------------+

.

--
http://lazaridis.com

James Edward Gray II

unread,
Apr 4, 2005, 11:55:20 AM4/4/05
to
On Apr 4, 2005, at 10:05 AM, Ilias Lazaridis wrote:

> James Edward Gray II wrote:
>> On Apr 4, 2005, at 9:04 AM, Ilias Lazaridis wrote:
>>>
>>> Is this book available online?
>> The first edition of the book (now in its second edition) is
>> available online, but the figures aren't in it. They are what you
>> are after.
>
> sad.

Never sad to support good authors in their craft so they can keep
supplying us with excellent resources, in my opinion.

I do believe Programming Ruby is well worth the cover charge. It
answers for me every question I've ever seen you ask here, and I'm
willing to bet it took me less time to read than it did for you to
compose all those emails. Just FYI.

James Edward Gray II

Ilias Lazaridis

unread,
Apr 4, 2005, 12:36:43 PM4/4/05
to
James Edward Gray II wrote:
> On Apr 4, 2005, at 10:05 AM, Ilias Lazaridis wrote:
>> James Edward Gray II wrote:
>>> On Apr 4, 2005, at 9:04 AM, Ilias Lazaridis wrote:
>>>>
>>>> Is this book available online?
>>>
>>> The first edition of the book (now in its second edition) is
>>> available online, but the figures aren't in it. They are what you
>>> are after.
>>
>> sad.
>
> Never sad to support good authors in their craft so they can keep
> supplying us with excellent resources, in my opinion.

please!

I reference only publicly available resources.

I would reference this book (it's online version), if it contained the
figures [and intrested people could by the book of course].

No figures - no reference - no publicity (from my document).

sad.

btw: is the diagramm an UML one?

> I do believe Programming Ruby is well worth the cover charge. It
> answers for me every question I've ever seen you ask here, and I'm
> willing to bet it took me less time to read than it did for you to
> compose all those emails. Just FYI.

I'm not intrested in books.

I'm intrested in providing an analysis / evaluation, which anyone can
follow without cost (except internet access).

[btw: I'm not payed to do this]

> James Edward Gray II

.

--
http://lazaridis.com

Florian Groß

unread,
Apr 4, 2005, 1:12:58 PM4/4/05
to
Ilias Lazaridis wrote:

>> I do believe Programming Ruby is well worth the cover charge. It
>> answers for me every question I've ever seen you ask here, and I'm
>> willing to bet it took me less time to read than it did for you to
>> compose all those emails. Just FYI.
>
> I'm not intrested in books.
>
> I'm intrested in providing an analysis / evaluation, which anyone can
> follow without cost (except internet access).

The question is whether those evaluations will indeed be useful to the
general public or more useful to yourself.

As far as I can see most of the content of it it is already available on
the web through the Pickaxe 1 book and I think it is odd to turn that
down just because you don't happen to get the figures with it.

And while I think it is nice that you are trying to understand this
language I think you should start with the basics. You're already asking
specific question about introspection when you have not yet understood
the difference of "obj.method" in Ruby and in Python.

Please, start with the basics.

I know that that will take more time, but by this point you will likely
agreed that Ruby *is* worth some time investment to learn it.

If you decide not to learn the basics then I think that your evaluations
will not be worth much anyway.

Don't take this as an attack to you. I think this community is friendly
and is not bothered by answering questions, but at some time it makes
sense to examine the resources that are already available in public.

Thanks for your attention.

Ilias Lazaridis

unread,
Apr 4, 2005, 1:29:20 PM4/4/05
to
Florian Groß wrote:
[...] - (several comments)

> Please, start with the basics.

[...]

> Don't take this as an attack to you. I think this community is friendly
> and is not bothered by answering questions, but at some time it makes
> sense to examine the resources that are already available in public.

Read this thread carefully.

You will find several cases where community members run on surprises.

> Thanks for your attention.

I've lost a little my process, as I found ruby intresting.

[Now, it's really time for me to close the thread, which has really an
exceptional in-topic-ratio]

.

--
http://lazaridis.com

0 new messages