[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[Documentation Bug] Method Missing

Brian Schröder

11/22/2004 7:32:00 PM

Just a minor typo in the documentation

-------------------------------------------------- Kernel#method_missing
obj.method_missing(symbol [, *args] ) => result
------------------------------------------------------------------------
Invoked by Ruby when obj is sent a message it cannot handle.
symbol is the symbol for the method called, and args are any
arguments that were passed to it. By default, the interpreter
raises an error when this method is called. However, it is
possible to override the method to provide more dynamic behavior.
The example below creates a class Roman, which responds to methods
with names consisting of roman numerals, returning the
corresponding integer values.

class Roman
def romanToInt(str)
# ...
end
def method_missing(methId)
str = methId.id2name
romanToInt(str)
end
end

r = Roman.new
r.iv #=> 4
r.xxiii #=> 23
r.mm #=> 2000

I think that it would make sense to gsub(/methId/, 'meth_id') to go with standard ruby dialect.

Regards,

Brian

--
Brian Schröder
http://www.brian-sch...



4 Answers

Brian Schröder

11/22/2004 9:02:00 PM

0

Another Thing I noticed. (I checked against the documentation at ruby-doc org. I hope that is the newest version.)


--------------------------------------------------------- Object#methods
obj.methods => array
------------------------------------------------------------------------
Returns a list of the names of methods publicly accessible in obj.
This will include all the methods accessible in obj's ancestors.

class Klass
def kMethod()
end
end
k = Klass.new
k.methods[0..9] #=> ["kMethod", "freeze", "nil?", "is_a?",
"class", "instance_variable_set",
"methods", "extend", "<em>send</em>", "instance_eval"]
k.methods.length #=> 42


$ ruby -v
ruby 1.8.2 (2004-11-03) [i386-linux]

$ irb --prompt-mode xmp
class Klass
def kMethod()
end
end
==>nil
k = Klass.new
==>#<Klass:0x402c00a4>
k.methods[0..9]
==>["clone", "protected_methods", "kMethod", "freeze", "instance_variable_set", "is_a?", "type", "methods", "method", "=~"]
k.methods.length
==>41


And additionally, here is again the snake_case against CamelCase issue.

Regards,

Brian

--
Brian Schröder
http://ruby.brian-sch...



Dave Thomas

11/22/2004 9:14:00 PM

0


On Nov 22, 2004, at 15:01, Brian Schröder wrote:

> Another Thing I noticed. (I checked against the documentation at
> ruby-doc org. I hope that is the newest version.)
> k.methods[0..9] #=> ["kMethod", "freeze", "nil?", "is_a?",
> "class", "instance_variable_set",
> "methods", "extend", "<em>send</em>",
> "instance_eval"]
> k.methods.length #=> 42
>

> k.methods[0..9]
> ==>["clone", "protected_methods", "kMethod", "freeze",
> "instance_variable_set", "is_a?", "type", "methods", "method", "=~"]
> k.methods.length
> ==>41
>

The documentation is correct, but the list of methods in Object has
changed.


As a matter of interest, are the ruby-doc folks now maintaining the
documentation?


Cheers

Dave




Gavin Sinclair

11/24/2004 5:43:00 AM

0

On Tuesday, November 23, 2004, 8:13:54 AM, Dave wrote:

> As a matter of interest, are the ruby-doc folks now maintaining the
> documentation?

No. When I get my CVS account back [1], the answer will be yes.

Gavin

[1] i.e. when I work out how to use GPG and SSH correctly.



Brian Schröder

11/24/2004 8:34:00 AM

0

On Tue, 23 Nov 2004 06:13:54 +0900
Dave Thomas <pragdave@gmail.com> wrote:

>
> On Nov 22, 2004, at 15:01, Brian Schröder wrote:
>
> > Another Thing I noticed. (I checked against the documentation at
> > ruby-doc org. I hope that is the newest version.)
> > k.methods[0..9] #=> ["kMethod", "freeze", "nil?", "is_a?",
> > "class", "instance_variable_set",
> > "methods", "extend", "<em>send</em>",
> > "instance_eval"]
> > k.methods.length #=> 42
> >
>
> > k.methods[0..9]
> > ==>["clone", "protected_methods", "kMethod", "freeze",
> > "instance_variable_set", "is_a?", "type", "methods", "method", "=~"]
> > k.methods.length
> > ==>41
> >
>
> The documentation is correct, but the list of methods in Object has
> changed.
>
>
> As a matter of interest, are the ruby-doc folks now maintaining the
> documentation?
>
>
> Cheers
>
> Dave
>
>

And regarding the two snake_case vs camelCase issues is this going to be changed?

Regards,

Brian


--
Brian Schröder
http://www.brian-sch...