Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Returning the names of each defined method
Kain Nobel
9/23/2008 8:00:00 AM
Good day everybody!
I was curious, for code that isn't veiwable, how would I print each
defined method in a class/module? For instance... lets say that File
happened to be a hidden class, how could I make the interpreter p or
print each method that is defined in class File?
--
Posted via
http://www.ruby-...
.
2 Answers
Brian Candler
9/23/2008 9:19:00 AM
0
Kain Nobel wrote:
> I was curious, for code that isn't veiwable, how would I print each
> defined method in a class/module? For instance... lets say that File
> happened to be a hidden class, how could I make the interpreter p or
> print each method that is defined in class File?
What do you mean by a "hidden class", or "code that isn't viewable"? If
the Ruby interpreter is able to read a .rb file, then so are you.
But in any case there are a number of reflection methods, for example:
irb(main):001:0> File.instance_methods - Object.instance_methods
=> ["select", "read", "<<", "lineno=", "tell", "mtime", "fileno",
"partition", "print", "rewind", "pid", "readpartial", "grep",
"readlines", "stat", "truncate", "tty?", "seek", "reject", "getc",
"binmode", "to_io", "ctime", "pos", "putc", "closed?", "member?",
"readchar", "find", "pos=", "close_read", "each_with_index",
"each_line", "lstat", "reopen", "to_i", "collect", "sysseek", "all?",
"entries", "fsync", "puts", "eof", "detect", "ungetc", "zip",
"each_byte", "flock", "close_write", "syswrite", "map", "any?", "ioctl",
"chmod", "sync", "sort", "include?", "min", "gets", "sync=", "flush",
"find_all", "write", "isatty", "each", "atime", "sysread", "inject",
"printf", "eof?", "fcntl", "path", "sort_by", "chown", "lineno", "max",
"readline", "close"]
For more info see
http://www.ruby-doc.org/docs/ProgrammingRuby/html/o...
--
Posted via
http://www.ruby-...
.
Siep Korteling
9/23/2008 9:24:00 AM
0
Kain Nobel wrote:
> Good day everybody!
>
> I was curious, for code that isn't veiwable, how would I print each
> defined method in a class/module? For instance... lets say that File
> happened to be a hidden class, how could I make the interpreter p or
> print each method that is defined in class File?
p File.methods
#or
puts File.methods.sort
# you can't use all these methods, some of them are private. To exclude
these:
puts File.public_methods.sort
# Works on instances, too.
puts "somestring".public_methods.sort
hth,
Siep
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Returning the names of each defined method
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password