Analysing ruby code

Discussion in 'Ruby' started by cypher.dp@gmail.com, May 22, 2007.

  1. Guest

    Hello everybody !

    Somebody knows the best way or even a tool to split ruby code into its
    different constructs ?
    For example:

    class Foo
    def initialize
    @x = "y"
    end

    def Bar(*args)
    if args[0]
    puts "Bar" + args[0]
    else
    puts @x
    end
    end
    end

    should be split into an Array

    ["class Foo\n", "def initialize\n\t@x="y"\nend\n", "def Bar(*args)\n",
    "if args[0].........

    Thanks a lot !

    Domenico
    , May 22, 2007
    #1
    1. Advertising

  2. On 5/22/07, <> wrote:
    > Hello everybody !
    >
    > Somebody knows the best way or even a tool to split ruby code into its
    > different constructs ?
    > For example:
    >
    > class Foo
    > def initialize
    > @x = "y"
    > end
    >
    > def Bar(*args)
    > if args[0]
    > puts "Bar" + args[0]
    > else
    > puts @x
    > end
    > end
    > end
    >
    > should be split into an Array
    >
    > ["class Foo\n", "def initialize\n\t@x="y"\nend\n", "def Bar(*args)\n",
    > "if args[0].........


    This looks like you are just splitting it into lines. If so then if
    it's in a file
    filename = 'myprog.rb'
    line_array = File.readlines(filename)

    Or if it's a string
    source = <<END
    class Foo
    def initialize
    @x = "y"
    end

    def Bar(*args)
    if args[0]
    puts "Bar" + args[0]
    else
    puts @x
    end
    end
    end
    END
    line_array = source.to_a

    --
    Rick DeNatale

    My blog on Ruby
    http://talklikeaduck.denhaven2.com/
    Rick DeNatale, May 22, 2007
    #2
    1. Advertising

  3. Guest

    No, it's a little bit more than just splitting it into lines.
    It's more that I want

    [beginning of class, methode 1, methode 2, if-construct in methode 2,
    the rest of methode 2, ...]

    so basicly every methode/class/if/... with their code as an own entry
    in an array.

    Domenico
    , May 22, 2007
    #3
  4. unknown wrote:
    > No, it's a little bit more than just splitting it into lines.
    > It's more that I want
    >
    > [beginning of class, methode 1, methode 2, if-construct in methode 2,
    > the rest of methode 2, ...]
    >
    > so basicly every methode/class/if/... with their code as an own entry
    > in an array.
    >
    > Domenico


    You can use the irb tokenizer to do that. I used it to create colored
    HTML. It takes a bit reading into it, though. But if you know ruby a bit
    it's doable.

    Regards
    Stefan

    --
    Posted via http://www.ruby-forum.com/.
    Stefan Rusterholz, May 22, 2007
    #4
  5. Luis Parravicini, May 22, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Rivers

    Analysing Xrunhprof data

    Bob Rivers, Aug 2, 2004, in forum: Java
    Replies:
    1
    Views:
    2,910
    Tris Orendorff
    Aug 2, 2004
  2. Xavier Seneque
    Replies:
    0
    Views:
    605
    Xavier Seneque
    Jul 9, 2005
  3. jmdeschamps
    Replies:
    4
    Views:
    422
    jmdeschamps
    Jan 19, 2004
  4. Andi Clemens

    Logfile analysing with pyparsing

    Andi Clemens, Sep 26, 2006, in forum: Python
    Replies:
    2
    Views:
    528
    Paul McGuire
    Sep 26, 2006
  5. Arjen van Schie

    code analysing tools for Ruby

    Arjen van Schie, Mar 28, 2007, in forum: Ruby
    Replies:
    1
    Views:
    176
    Zev Blut
    Mar 29, 2007
Loading...

Share This Page