Respond_to? in mod_ruby

<%
def blah
end
p respond_to? “blah”
%>

==> false

anyone know why? And how to get around?

db

···


Feb 12 Abraham Lincoln born, 1809
Feb 12 Charles Darwin born in Shrewsbury, England, 1809
Feb 12 Lincoln’s real birthday
Feb 12 Santa Barbara oil leak, 1969
Feb 12 Pyidaungsa Day in Burma
Feb 12 The Beatles play Carnegie Hall in New York City, 1964
Feb 12* Rosh Chodesh Adar (Beginning of the month of Adar)

Daniel Bretoi wrote:

<%
def blah
end
p respond_to? “blah”
%>

==> false

anyone know why? And how to get around?

$ irb
irb(main):001:0> def blah
irb(main):002:1> end
nil
irb(main):003:0> p respond_to? “blah”
false
nil

Doesn’t look to me like mod_ruby is part of the problem equation
atleast.

def blah
end
p self.respond_to? “blah”, true

From
http://www.rubycentral.com/book/ref_c_object.html#Object.respond_to_qm
“Private methods are included in the search only if the optional second
parameter evaluates to true.”

HTH

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

batsman@tux-chan:~/src/cvs/ruby$ irb
irb(main):001:0> def bla
irb(main):002:1> end
=> nil
irb(main):003:0> p respond_to? “bla”
true
=> nil
irb(main):004:0>
batsman@tux-chan:~/src/cvs/ruby$ irb1.7
irb(main):001:0> def bla
irb(main):002:1> end
nil
irb(main):003:0> p respond_to? “bla”
(irb):3: warning: parenthesize argument(s) for future version
false
nil
irb(main):004:0> p respond_to? “bla”, true
(irb):4: warning: parenthesize argument(s) for future version
true
nil
irb(main):005:0> p respond_to?(“bla”, true)
true
nil

···

On Thu, Feb 13, 2003 at 05:48:04PM +0900, Kent Dahl wrote:

Daniel Bretoi wrote:

<%
def blah
end
p respond_to? “blah”
%>

==> false

anyone know why? And how to get around?

$ irb
irb(main):001:0> def blah
irb(main):002:1> end
nil
irb(main):003:0> p respond_to? “blah”
false
nil

Doesn’t look to me like mod_ruby is part of the problem equation
atleast.

def blah
end
p self.respond_to? “blah”, true

From
http://www.rubycentral.com/book/ref_c_object.html#Object.respond_to_qm
“Private methods are included in the search only if the optional second
parameter evaluates to true.”


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Turn right here. No! NO! The OTHER right!

We seem to get different results.

[~]$ ruby -version
ruby 1.6.8 (2002-12-24) [i386-linux]

irb(main):001:0> def blah
irb(main):002:1> end
=> nil
irb(main):003:0> p respond_to? “blah”
true
=> nil

After doing a p private_methods, every single method in my
mod_ruby scripts show up as private, even though non have been declared
as such. Is this a safety feature of mod_ruby?

db

···

On Thu, Feb 13, 2003 at 05:48:04PM +0900, Kent Dahl wrote:

Daniel Bretoi wrote:

<%
def blah
end
p respond_to? “blah”
%>

==> false

anyone know why? And how to get around?

$ irb
irb(main):001:0> def blah
irb(main):002:1> end
nil
irb(main):003:0> p respond_to? “blah”
false
nil

Doesn’t look to me like mod_ruby is part of the problem equation
atleast.

def blah
end
p self.respond_to? “blah”, true

From
http://www.rubycentral.com/book/ref_c_object.html#Object.respond_to_qm
“Private methods are included in the search only if the optional second
parameter evaluates to true.”

HTH


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __?|?// ) )Industrial economics and technological management(
_
/?____/ (_engineering.discipline=Computer::Technology)


Feb 13* Be happy, It’s Adar !
Feb 13* Rosh Chodesh Adar (Beginning of the month of Adar)

When you define “functions” as in

def bla
end

you’re in fact defining private instance methods of Object.

See [58056]

···

On Fri, Feb 14, 2003 at 05:06:03AM +0900, Daniel Bretoi wrote:

We seem to get different results.

[~]$ ruby -version
ruby 1.6.8 (2002-12-24) [i386-linux]

irb(main):001:0> def blah
irb(main):002:1> end
=> nil
irb(main):003:0> p respond_to? “blah”
true
=> nil

After doing a p private_methods, every single method in my
mod_ruby scripts show up as private, even though non have been declared
as such. Is this a safety feature of mod_ruby?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

abuse me. I’m so lame I sent a bug report to debian-devel-changes
– Seen on #Debian

Daniel Bretoi wrote:

We seem to get different results.
[~]$ ruby -version
ruby 1.6.8 (2002-12-24) [i386-linux]

Sorry about that, i’m on an older version:
$ ruby -v
ruby 1.6.7 (2002-03-01) [i586-linux-gnu]

irb(main):001:0> def blah
irb(main):002:1> end
=> nil
irb(main):003:0> p respond_to? “blah”
true
=> nil

After doing a p private_methods, every single method in my
mod_ruby scripts show up as private, even though non have been declared
as such. Is this a safety feature of mod_ruby?

All methods defined at the toplevel scope go into an Object as a private
method, IIRC.
From the Pickaxe:
http://www.rubycentral.com/book/classes.html#S3
“At the top level, we’re executing code in the context of some
predefined object. When we define methods, we’re actually creating
(private) singleton methods for this object.”

But then the Pickaxe was wrong on how that method worked, so YMMV :slight_smile:

As for mod_ruby, the code will be wrapped in an anonymous module. I am
uncertain how that affects respond_to? and where “toplevel” methods
go.

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)