This is a console-based Train Management Application where I practiced Object-Oriented Programming (OOP) principles, exception handling, and metaprogramming.
- Object-Oriented design with encapsulation, inheritance, and polymorphism.
- Exception handling for better error management.
- Metaprogramming techniques to dynamically define methods and enhance flexibility.
- Custom validation system with DSL for data validation (presence, format, type checks).
- Interactive terminal menu using
tty-prompt.
The application allows users to:
- Create and manage trains, routes, and stations.
- Assign routes to trains and control train movement.
- View and modify train details through an interactive menu.
Install required Ruby gems with Bundler:
bundle installTo start the application, run:
ruby main.rbThe project includes a custom validation module that provides a DSL for data validation:
class ExampleClass
include Validation
validate :attribute, :presence # Checks that attribute is not nil/empty
validate :number, :format, /\d{3}-\d{2}/ # Validates format with regex
validate :object, :type, String # Validates object type
def initialize
validate! # Raises ValidationError on failure
end
def valid?
validate! # Returns true/false, prints errors
rescue ValidationError
false
end
endThe validation system uses metaprogramming to dynamically call appropriate validators and supports inheritance for custom validation logic in subclasses.