[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02765] Re: More code browsing questions

From: Dave Thomas <Dave@...>
Date: 2000-05-12 02:19:06 UTC
List: ruby-talk #2765
Albert Wagner <alwagner@tcac.net> writes:

> I see some class definitions contain "include" and "extend" statements. 
> I can find no doc refs to these.  Also, "autoload".  If these are in the
> manual or user guide, please point me in the right direction.  Is there
> an english translation to ruby-1.4.4/ext/tcltklib/MANUAL.euc?  Thanks
> ahead for any help.

Both include and extend take one or more modules and add their methods 
and constants in to something: include adds in to a class definition,
which extend adds to a particular object.

For example

  module Cheery
    def hello
      puts "Toodle-pip, old chap!"
    end
  end

  class Person
    include Cheery
    def other
      puts "other"
    end
  end

  p = Person.new
  p.hello    #=> Toodle-pip, old chap!
  p.other    #=> other


  s = "A String"
  s.extend Cheery
  s.hello    #=> Toodle-pip, old chap!


Every language needs Cheery strings.



Dave

In This Thread