Professional Web Applications Themes

Method Reflection - Ruby

I'm quite new to ruby and was amazed by the powerful reflection mechanism, so tried to use the tracing function to yse the object space of our project. It was amazingly easy to dump module,class and method definitions to xml as they occured, but i was not able to retrieve any information about the formal method parameters (correct term?), neither the number nor the name. I wasn't able to retrieve information on instance variables as well. Is it possible ? If this kind of information retrieval is considered useful, I would also suggest to add in-language comments as in python ...

  1. #1

    Default Method Reflection

    I'm quite new to ruby and was amazed by the powerful reflection
    mechanism, so tried to use the tracing function to yse the object
    space of our project.

    It was amazingly easy to dump module,class and method definitions to xml
    as they occured, but i was not able to retrieve any information about
    the formal method parameters (correct term?), neither the number nor the
    name. I wasn't able to retrieve information on instance variables as
    well. Is it possible ?

    If this kind of information retrieval is considered useful, I would also
    suggest to add in-language comments as in python (especially if the irb
    gets faster and more user friendly ;) )


    ad emacs) Fixnum character literals mess up brace matching ( ?( ,?) ),
    but this could be hard to fix. Is there a syntax-highlighting patch ?





    Benedikt Guest

  2. #2

    Default Re: Method Reflection

    Benedikt Huber wrote:
     
    http://www.rubycentral.com/book/ref_c_method.html

    arity gives the number of parameters (check the special cases in the doc
    with method with variable number of parameters -with optional parameters-).

    irb(main):001:0> a = String.new
    => ""
    irb(main):002:0> a.method('split').arity
    => -1
    irb(main):004:0> a.method('insert').arity
    => 2

    i'm afraid you can't get the name of the parameters at runtime (this is
    a job for rdoc).
     

    Apparently there is a instance_variables method.

    emmanuel



    Emmanuel Guest

  3. #3

    Default Re: Method Reflection / Keyword Arguments

    "Emmanuel Touzery" <fr> wrote:
     

    When Ruby supports keyword arguments, will the names of keyword method
    parameters be included as part of the method selector (as done in
    Smalltalk)? And will they be available at runtime to reflection?



    Its Guest

  4. #4

    Default Re: Method Reflection

    il Mon, 2 Feb 2004 15:00:41 +0900, Benedikt Huber <net> ha
     


    arity() is your friend. About names: we'll see keyword arguments in
    ruby2
     

    probably yuo mean docstrings. I asked this once and matz answered that
    this won't make it in ruby. But you can use the MetaTags module for
    this (yes, ruby is impressively flexible :).
    Or, post an RCR on rcrchive.net :)


    gabriele Guest

Similar Threads

  1. Reflection map?
    By Pelleyoo in forum Macromedia Director 3D
    Replies: 6
    Last Post: April 16th, 05:09 PM
  2. Replies: 2
    Last Post: March 15th, 09:59 AM
  3. [PHP-DEV] reflection api -> camelcaps
    By George in forum PHP Development
    Replies: 10
    Last Post: December 3rd, 01:58 AM
  4. Problem with reflection
    By Holger Mescheder in forum Macromedia Director Lingo
    Replies: 0
    Last Post: November 18th, 07:07 PM
  5. Self Reflection
    By Beth Haney in forum Adobe Photoshop Elements
    Replies: 3
    Last Post: August 1st, 02:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139