Ruby/Tk article on macdevcenter

Hadn't seen this mentioned yet:

http://www.macdevcenter.com/pub/a/mac/2004/06/25/ruby_pt1.html

Phil

Phil Tomson wrote:

Hadn't seen this mentioned yet:

Radar – O’Reilly

Phil

Timely. I'm just about to embark on my first Ruby/Tk application.

That "default initialize" method, though, the one with no arguments. That's
just not right. I believe the 2nd definition of initialize is going to
override the "default" one. Let's see:

[tim: ~]$ ruby -w rb/CronJobMgr.rb
rb/CronJobMgr.rb:95: warning: method redefined; discarding old initialize

Yup.

Sadly the guy seems rather new to Ruby - his overloaded initialize method
is a glaring C++ism. I've written to him about it; hopefully the code
can be changed.

martin

···

Phil Tomson <ptkwt@aracnet.com> wrote:

Hadn't seen this mentioned yet:

Radar – O’Reilly

this made me notice this:
ruby -e "self.puts 'ciao' "
-e:1: private method `puts' called for main:Object (NoMethodError)

why this error appears?

···

il 19 Jul 2004 21:37:37 GMT, ptkwt@aracnet.com (Phil Tomson) ha scritto::

Hadn't seen this mentioned yet:

Radar – O’Reilly

gabriele renzi wrote:

il 19 Jul 2004 21:37:37 GMT, ptkwt@aracnet.com (Phil Tomson) ha
scritto::

Hadn't seen this mentioned yet:

Radar – O’Reilly

this made me notice this:
ruby -e "self.puts 'ciao' "
-e:1: private method `puts' called for main:Object (NoMethodError)

why this error appears?

puts is - as the error message says, a privat method.
In Ruby - if memory serves right - private methods can only be called with an implicit receiver.

A citation from the pickaxe: "Private methods cannot be called with an explicit receiver. Because you cannot specify an object when using them, private methods can be called only in the defining class and by direct descendents within that same object."

Stephan

puts is - as the error message says, a privat method.
In Ruby - if memory serves right - private methods can only be called
with an implicit receiver.

svg% ruby -e 'Kernel.puts "I am a Kernel module function"'
I am a Kernel module function
svg%

Guy Decoux

puts is - as the error message says, a privat method.
In Ruby - if memory serves right - private methods can only be called
with an implicit receiver.

svg% ruby -e 'Kernel.puts "I am a Kernel module function"'
I am a Kernel module function

well, but since

self.kind_of? Kernel

=> true
then why self.puts fails?
Is the explanation
"you can't call methods in included modules with self.method" ?

···

il Wed, 21 Jul 2004 00:06:13 +0900, ts <decoux@moulon.inra.fr> ha scritto::

"you can't call methods in included modules with self.method" ?

yes and no

a module function is a private method and a public class method.

When you include a module, you have access only to the methods (not the
class methods). If an object, except Kernel, try to access puts it
will have the private method

Guy Decoux