Ruby's standard objects

S

Stephan Kämper

Hi group,

as I'm (kind of) browsing ObjectSpace I wonder if there's a way to
dynamically collect a list of the names of the standard objects and
global constants of Ruby (you know STDOUT, ARGV, DATA, RUBY_VERSION etc.)?

Is there a way to get these names? (And if so how would you suggest to
collect it?)

Happy rubying

Stephan
 
P

Peter

Hi group,
as I'm (kind of) browsing ObjectSpace I wonder if there's a way to
dynamically collect a list of the names of the standard objects and
global constants of Ruby (you know STDOUT, ARGV, DATA, RUBY_VERSION etc.)?

Is there a way to get these names? (And if so how would you suggest to
collect it?)

Do you mean this?

irb(main):001:0> Object.constants
=> ["TRUE", "SystemStackError", "RubyLex", "MatchData", "StandardError",
"ThreadError", "Float", "Tempfile", "SimpleDelegater", "RuntimeError",
"RUBY_RELEASE_DATE", "SimpleDelegator", "Continuation", "STDERR",
"Enumerable", "Object", "ObjectSpace", "NameError", "Errno", "Data",
"Process", "SignalException", "LoadError", "TOPLEVEL_BINDING", "Time",
"UnboundMethod", "Kernel", "IndexError", "NilClass", "STDIN",
"Comparable", "File", "Fixnum", "EOFError", "SystemCallError", "Dir",
"FloatDomainError", "ThreadGroup", "Class", "Precision", "ScriptError",
"RELEASE_DATE", "Symbol", "ARGV", "FalseClass", "Proc", "MatchingData",
"Readline", "GC", "TypeError", "String", "Thread", "SecurityError", "ENV",
"Binding", "NoMethodError", "RUBY_PLATFORM", "Delegator", "Regexp",
"Interrupt", "Integer", "SLex", "TrueClass", "NotImplementedError", "IO",
"Delegater", "Bignum", "Range", "RangeError", "STDOUT", "RUBY_VERSION",
"IRB", "RegexpError", "Numeric", "Hash", "Exception2MessageMapper",
"RubyToken", "Kconv", "SyntaxError", "Exception", "Signal", "PLATFORM",
"FALSE", "Array", "ArgumentError", "FileTest", "Struct",
"ZeroDivisionError", "NoMemoryError", "SystemExit", "IOError",
"LocalJumpError", "Math", "Marshal", "ARGF", "NIL", "Module", "Method",
"VERSION"]

Peter
 
S

Stephan Kämper

Hi Peter,
Do you mean this?

irb(main):001:0> Object.constants
=> ["TRUE", "SystemStackError", "RubyLex", "MatchData", "StandardError",
....snipped some constant names...
"VERSION"]

Yes, that's exactly what I meant. Thanks a lot.
Amazing, I'm surprised again just _how_ easy things are with Ruby.
Actually, I admit that this time I'm surprised by the principle of the
least surprise (which might not be as paradox as it seems at first
sight). Matz, thanks for this language. :)

Happy rubying

Stephan
 
R

Robert Klemme

Stephan Kämper said:
Hi Peter,
Do you mean this?

irb(main):001:0> Object.constants
=> ["TRUE", "SystemStackError", "RubyLex", "MatchData",
"StandardError",
...snipped some constant names...
"VERSION"]

Yes, that's exactly what I meant. Thanks a lot.
Amazing, I'm surprised again just _how_ easy things are with Ruby.
Actually, I admit that this time I'm surprised by the principle of the
least surprise (which might not be as paradox as it seems at first
sight). Matz, thanks for this language. :)

Additonally there is

irb(main):001:0> global_variables
=> ["$-w", "$stderr", "$LOAD_PATH", "$<", "$-0", "$+", "$-p", "$$", "$-i",
"$deferr", "$~", "$!", "$-v", "$stdout", "$_", "$-K", "$-F", "$SAFE",
"$*", "$-I", "$/", "$'", "$-d", "$FILENAME", "$defout", "$@", "$VERBOSE",
"$stdin", "$.", "$KCODE", "$;", "$binding", "$0", "$:", "$,", "$`",
"$DEBUG", "$>", "$-a", "$\"", "$\\", "$=", "$-l", "$?", "$&"]

Regards

robert
 

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

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,370
Latest member
desertedtyro29

Latest Threads

Top