Ruby/Tk article on macdevcenter

T

Tim Hunter

Phil said:

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

Stephan Kämper

gabriele said:
il 19 Jul 2004 21:37:37 GMT, (e-mail address removed) (Phil Tomson) ha
scritto::




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
 
T

ts

"S" == =?ISO-8859-1?Q?Stephan K=E4mper?= <ISO-8859-1> writes:

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

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



Guy Decoux
 
G

gabriele renzi

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

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

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

ts

g> "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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top