What is an easy way to find out what methods/properties that a ruby object exposes?
As an example to get member information for a string, in PowerShell, you can do
"" | get-member
In Python,
dir("")
Is there such an easy way to discover member information of a Ruby object?
The proper way to determine the "type" of an object, which is a wobbly term in the Ruby world, is to call object. class . Since classes can inherit from other classes, if you want to determine if an object is "of a particular type" you might call object.
In `ruby`, the body of an object is expressed by a struct and always handled via a pointer. A different struct type is used for each class, but the pointer type will always be `VALUE` (figure 1). In practice, when using a `VALUE`, we cast it to the pointer to each object struct.
Practically everything in Ruby is an Object, with the exception of control structures. Whether or not under the covers a method, code block or operator is or isn't an Object, they are represented as Objects and can be thought of as such.
"foo".methods
See:
http://ruby-doc.org/core/classes/Object.html
http://ruby-doc.org/core/classes/Class.html
http://ruby-doc.org/core/classes/Module.html
Ruby doesn't have properties. Every time you want to access an instance variable within another object, you have to use a method to access it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With