Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby modules that contain classes

Tags:

ruby

I am working on a project to create a compiler in Ruby, even simple compilers will still have a lot of code. I plan on having classes like SymbolTable, Lexer,Parser etc....

All of these classes perform specific operations, but I would still like to group them under one namespace, is it possible to do this in separate files?

ex:

File#1 SymbolTable.rb

module PL0Compiler
  class SymbolTable
     #....
  end
end

File#2 Lever.rb

module PL0Compiler
  class Lexer
     #....
  end
end
like image 959
Hunter McMillen Avatar asked May 18 '26 06:05

Hunter McMillen


1 Answers

Yes, it is. But it would have taken you less time to try it out than to ask, so it's a weird question. Maybe you don't know how to access it? Here is a rather elaborate example.

like image 187
Joshua Cheek Avatar answered May 21 '26 09:05

Joshua Cheek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!