Google


   


You are here: CodeIdol.com > Other > Ruby Cookbook > Reflection And Metaprogramming

SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

Ruby Cookbook



Recipe 10.1. Finding an Object's Class and Superclass Problem Given a class, you want an object corresponding to its class, or to the parent of its class. Solution Use the Object#class method to get the class of an object as a Cla...



Recipe 10.2. Listing an Object's Methods Problem Given an unfamiliar object, you want to see what methods are available to call. Solution All Ruby objects implement the Object#methods method. It returns an array containing th...



Recipe 10.3. Listing Methods Unique to an Object Problem When you list the methods available to an object, the list is cluttered with extraneous methods defined in the object's superclasses and mixed-in modules. You want to see a list of only t...



Recipe 10.4. Getting a Reference to a Method Problem You want to the name of a method into a reference to the method itself. Solution Use the eponymous Object#method method: s = 'A string' length_method = s.method(:length) # =>...



Recipe 10.5. Fixing Bugs in Someone Else's Class Problem You're using a class that's got a bug in one of its methods. You know where the bug is and how to fix it, but you can't or don't want to change the source file itself. Solutions ...



Recipe 10.6. Listening for Changes to a Class Credit: Phil Tomson Problem You want to be notified when the definition of a class changes. You might want to keep track of new methods added to the class, or existing methods that get removed...



Recipe 10.7. Checking Whether an Object Has Necessary Attributes Problem You're writing a class or module that delegates the creation of some of its instance variables to a hook method. You want to be make sure that the hook method actuall...



Recipe 10.8. Responding to Calls to Undefined Methods Problem Rather than having Ruby raise a NoMethodError when someone calls an undefined method on an instance of your class, you want to intercept the method call and do something else...



Recipe 10.9. Automatically Initializing Instance Variables Problem You're writing a class constructor that takes a lot of arguments, each of which is simply assigned to an instance variable. class RGBColor(red=0, green=0, blue=0) ...



Recipe 10.10. Avoiding Boilerplate Code with Metaprogramming Problem You've got to type in a lot of repetitive code that a trained monkey could write. You're resentful at having to do this yourself, and angry that the repetitive code will ...



Recipe 10.11. Metaprogramming with String Evaluations Problem You're trying to write some metaprogramming code using define_method, but there's too much reflection going on for your code to be readable. It gets confusing and is almost as frustr...



Recipe 10.12. Evaluating Code in an Earlier Context Problem You've written a method that evaluates a string as Ruby code. But whenever anyone calls the method, the objects referenced by your string go out of scope. Your string can't be eva...



Recipe 10.13. Undefining a Method Problem You want to remove an already defined method from a class or module. Solution From within a class or module, you can use Module#remove_method to remove a method's implementation, forcing R...



Recipe 10.14. Aliasing Methods Problem You (or your users) frequently misremember the name of a method. To reduce the confusion, you want to make the same method accessible under multiple names. Alternatively, you're about to redefine a m...

read more: Aliasing Methods


Recipe 10.15. Doing Aspect-Oriented Programming Problem You want to "wrap" a method with new code, so that calling the method triggers some new feature in addition to the original code. Solution You can arrange for code to be called ...


SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

You are here: CodeIdol.com > Other > Ruby Cookbook > Reflection And Metaprogramming


ADBRITE ads links
   
Related tags







Popular Categories
Unix books and guides

AJAX popular information
C# language guides
Windows books and cookbooks

.......








Business Key Top Sites

be number one
rate your site


таблички металл

    С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.

    Русский Polski Francais Deutsch
    support sitemap terms

© CodeIdol Labs, 2007 - 2009