SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    execute from inside ruby

    how to execute a ruby program which is inside a string ?
    for example
    in
    name.rb

    puts "start "
    temp="(1..10).each do |count| print count end "
    puts "end"


    how to execute the source code in temp(String object)

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not quite sure what you are trying to do, but this is the code I use to run a command that backs up my SVN repository. It shows how you can run an external command from within a Ruby code. This example code runs on a Windows Vista system hence the C;\ path, but the technique will work on any OS.
    Code:
    def run(command)
      IO.popen(command, 'r+') do |io|
        io.close_write
        output = io.readlines
        for line in output
          puts line
        end
      end
    end
    
    run('svnadmin dump C:\Users\reggieb\Projects\SVNRepository > svndump.dmp')

  3. #3
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eval "puts 'hi'"
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as samsm said:

    adding
    Code ruby:
    eval(temp)
    should do the trick granted you don't have any syntax errors or anything in temp
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.


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
  •