A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

Units vs Ruby Modules


Modern Pascal uses units to keep functions and data structures inside its own namespace. Ruby can use modules. Modules don't require an instance of a class to be created, so they are like a namespace.
module test

  def test1
    puts 'this is test 1'
  end

  def test2
    puts 'this is test 2'
  end

  def test3
    puts 'this is test 3'
  end

end 

include test

# no instance needs to be created
test.test1
test.test2
test.test3

No complaints really. We can do good old procedural coding by avoiding using nonsensical classes for everything (well technically the functions are part of the self class that you can't see, but for creeps sake I'm not gonna get purist about it)

About
This site is about programming and other things.
_ _ _