The Artima Developer Community
Sponsored Link

Web Buzz Forum
Easy Introspection in Ruby

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Cheah Chu Yeow

Posts: 883
Nickname: redemption
Registered: Jun, 2003

Cheah Chu Yeow is no one of any importance
Easy Introspection in Ruby Posted: Aug 9, 2006 4:22 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Cheah Chu Yeow.
Original Post: Easy Introspection in Ruby
Feed Title: redemption in a blog
Feed URL: http://blog.codefront.net/xml/rss20/feed.xml
Feed Description: ramblings of a misfit - web development, Mozilla, Firefox, Thunderbird, CSS, programming
Latest Web Buzz Posts
Latest Web Buzz Posts by Cheah Chu Yeow
Latest Posts From redemption in a blog

Advertisement

Just some notes on reflection and introspection in Ruby

someString = 'http://google.com'

# Print the object's class, methods, superclass and
# ancestors (mixins and superclasses),
p someString.class
p someString.methods
p someString.class.superclass
p someString.class.ancestors

# Print the methods of the String class.
p String.private_instance_methods(false)
p String.public_instance_methods(false)

# Pass true to recurse into parent classes.
p String.public_instance_methods(true)

# Calling instance methods with send().
"Random text".send(:length) # 11
-23.send(:succ) # 22

# Using Method objects and call().
length_method = "Random text".method(:length)
length_method.call # 11

# Another way, using eval().
length_method = %q{"Random text".length}
eval length_method

Check out Distributed Ruby (DRb): it’s a very neat, non-fancy way of exposing object methods as remote services.

Read: Easy Introspection in Ruby

Topic: Microsoft Counters Windows Genuine Advantage False Positive Identification Accusations Previous Topic   Next Topic Topic: Free Java Source For DNS Server

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use