Professional Web Applications Themes

Methods outside classes - Ruby

Hi all, I've got a little curiosity about defining methods. As far as I know (and maybe I'm wrong) functions doesn't exist in Ruby... right? Ruby only have methods. However, I can do this: <code> #!/usr/bin/env ruby def test puts "This is a test" end test </code> If test is really a method... what class it belongs to? Or is it a function and I've missed something? Thank you. PD: OK, I know, I'm more worried about conceptual point of view that I'd must be ;-) -- (o_.' Imobach González Sosa net //\c{} es ulpgc.es V__)_ net osoh en jabber.at ...

  1. #1

    Default Methods outside classes

    Hi all,

    I've got a little curiosity about defining methods. As far as I know (and
    maybe I'm wrong) functions doesn't exist in Ruby... right? Ruby only have
    methods.

    However, I can do this:

    <code>
    #!/usr/bin/env ruby

    def test
    puts "This is a test"
    end

    test
    </code>

    If test is really a method... what class it belongs to? Or is it a function
    and I've missed something?

    Thank you.

    PD: OK, I know, I'm more worried about conceptual point of view that I'd must
    be ;-)

    --
    (o_.' Imobach González Sosa net
    //\c{} es ulpgc.es
    V__)_ net osoh en jabber.at y jabber.org
    Usuario Linux #201634
    Debian GNU/Linux `Sarge' con núcleo 2.4.24 sobre Intel Pentium 4

    La buena y verdadera amistad no debe ser sospechosa en nada.
    -- Miguel de Cervantes Saavedra. (1547-1616) Escritor español.




    Imobach Guest

  2. #2

    Default Re: Methods outside classes

    Imobach González Sosa wrote:
     
    That's right
     
    test is added as a private method of the class Object.
     
    HTH

    Best Regards

    Mark Sparshatt



    Mark Guest

  3. #3

    Default Re: Methods outside classes

    Some languages draw hard distinctions between "methods", "functions",
    "subroutines", etc., but Ruby's much more laid-back than that. You'll
    notice a similar sort of looseness with and variables, which can
    act differently if they're declared at a global scope than if they're
    declared within a class or method definition.

    (Now, if you get seriously into Ruby's more functional aspects you'll
    have to learn the differences between procs and lambdas, but you can
    still do a lot without learning that stuff.)

    Francis

    "Imobach González Sosa" <net> wrote in message news:<net>... 
    Francis Guest

  4. #4

    Default Re: Methods outside classes

    Francis Hwang wrote: 

    What is the technical definition right now? And which part is
    implemented and which parts are future changes?

    As far as I understood it, lambda's introduced a complete new scope so
    you could shadow variables above, whereas procs produced a more loose
    scope. But perhaps I misunderstood. Anyone have a good definition/example?

    Charles Comstock
    Charles Guest

Similar Threads

  1. Replies: 2
    Last Post: December 3rd, 12:47 AM
  2. Desperate: share base classes/methods across control assemblies?
    By Sky Sigal in forum ASP.NET Building Controls
    Replies: 0
    Last Post: August 4th, 09:31 PM
  3. adding methods to classes
    By tony in forum PHP Development
    Replies: 2
    Last Post: February 8th, 07:22 PM
  4. Replies: 1
    Last Post: September 16th, 12:05 PM
  5. "Shared" Methods in asp.net files/classes
    By Jenna in forum ASP.NET General
    Replies: 2
    Last Post: August 15th, 11:20 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