3/24/2008

Define Class Method in Ruby

Today, I study the way to define class method in ruby.

This way help me to make tiny utility function.

Following codes are the way.

  1. module MyModule
  2. class Utility
  3. def Utility.writingSignLine(f)
  4. f.print "#"
  5. for i in 0...77
  6. f.print "="
  7. end
  8. f.print "\n"
  9. end
  10. end
  11. end

Keynote is the 3 line.

This line expresses to define next codes as class method code.

Calling way is simple.

It's next!

  1. f = open(file_name, "w")
  2. MyModule::Utility::writingSignLine(f)

No comments: