[Ruby] Определение "+" и перестановка слагаемых

Ilya Palagin tux at fioc.kz
Wed Oct 2 09:56:33 MSD 2002


Здравствуйте,

К письму приложен файл с кодом. Интересно было бы узнать, как и где
определить метод "+", чтобы скрипт работал с 33-й строкой, т.е. при
перестановке слагаемых?

Спасибо.

-------------- next part --------------
#!/usr/bin/ruby

require 'cgi'
cgi = CGI.new("html3")


class PageElement
  def initialize(cgi)
	@cgi = cgi
	@var = @cgi.h3{}
  end
  def h(text)
	@var = @cgi.h3{text}
  end
  def to_s
	return @var
  end
  def +(var)
  	return (self.to_s + var)
  end
end

te = PageElement.new(cgi)
te.h("Hi there")

cgi.out{
  CGI.pretty (
    cgi.html{
      cgi.head{
		cgi.title{"Test Report"}
	  }+
      cgi.body{ 
		#cgi.h1{"Some text"} + te # Error
		te + cgi.h1{"Some text"} # No error
	  }
	}
  )
}



More information about the Ruby mailing list