Ruby coding help

Discussion in 'Ruby' started by Tridib Bandopadhyay, Feb 10, 2011.

  1. Hello All

    I want to code a method within a ruby source code. Is there any syntax
    to call that method(Which I coded) while writing a program in ruby. If
    so can anyone share it?

    Regards

    Tridib
     
    Tridib Bandopadhyay, Feb 10, 2011
    #1
    1. Advertisements

  2. Tridib Bandopadhyay

    Stu Guest

    Stu, Feb 10, 2011
    #2
    1. Advertisements

  3. Tridib Bandopadhyay wrote in post #980711:
    Certainly. What exactly are you trying to do?

    You can run arbitrary code from a string using eval(), or from a file
    using load(). This code can define methods.

    Once a method is defined, then you can just call it in the usual way.

    If you want to call a method with a name which is not known until
    runtime, use send().
    whee!
    => nilwhee!
    => nil
     
    Brian Candler, Feb 10, 2011
    #3
  4. hi Tridib,

    Ruby methods : It provides a way to organize code and promote re-use.
    Rather than create long sections of Ruby code, the code is instead
    organized into logical groups that can be called when needed and re-used
    without having to re-write the same code over and over. Methods are
    simple to use, in fact you only need to do two things with a method,
    declare it and call it.

    How to declaring and Calling a Ruby Method

    The syntax of a Ruby method is as follows:

    def name( arg1, arg2, arg3, ... )
    .. ruby code ..
    return value
    end

    The name specifies how we will refer to this method when we call it. The
    args specify values that are passed through to the method to be
    processed. The ruby code section represents the body of the function
    that performs the processing. The optional return statement allows a
    value to be returned to the section of code which called the method.
     
    Basant Dewangan, Feb 10, 2011
    #4
  5. No. My query was... I am going to type in a method within some file of
    Ruby.. like gc.c and will call that method from Ruby Code..... like

    I will code a free method within source code and will call that function
    from a ruby code while coding..... So it is possible... if so what is
    the syntax to call the method.

    Regards

    Tridib
     
    Tridib Bandopadhyay, Feb 14, 2011
    #5
  6. Any suggestion to my previous query.

    Tridib
     
    Tridib Bandopadhyay, Feb 28, 2011
    #6
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.