# ruby_study **Repository Path**: cutecuteyu/ruby_study ## Basic Information - **Project Name**: ruby_study - **Description**: ruby_study - **Primary Language**: Ruby - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-23 - **Last Updated**: 2026-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Ruby Learning Project This is a comprehensive Ruby learning project containing complete tutorials and example code from basic syntax to advanced features. ## 📚 Project Contents This project includes the following main learning modules: ### 1. Ruby Basic Tutorial (`ruby-tutorial.md`) A complete Markdown tutorial document covering all the basics of Ruby: - Ruby introduction and features - Ruby installation guide (Windows/macOS/Linux) - Ways to run Ruby code - Basic syntax detailed explanation - Common development tools - Suggested learning path **Quick Start:** ```bash # Read the tutorial cat ruby-tutorial.md ``` --- ### 2. Ruby Basic Syntax Tutorial (`ruby_tutorial/`) Learn Ruby basic syntax through executable example code. Each topic has a separate file with detailed Chinese comments. #### File List: | File | Content | |------|---------| | `00_main.rb` | Main entry file, runs all examples | | `01_variables.rb` | Variable types (local, constant, global, instance, class variables) | | `02_data_types.rb` | Data types (integers, floats, strings, arrays, hashes, etc.) | | `03_input_output.rb` | Input/Output (puts, print, p, gets) | | `04_conditionals.rb` | Conditionals (if, unless, case, ternary operator) | | `05_loops.rb` | Loops (times, while, for, each) | | `06_methods.rb` | Methods (parameters, return values, variable arguments, keyword arguments) | | `07_classes.rb` | Classes and Objects (inheritance, access control, method overriding) | **How to Run:** ```bash # Run all examples cd ruby_tutorial ruby 00_main.rb # Run a single example ruby 01_variables.rb ``` --- ### 3. Ruby Module System Deep Dive (`module_test/`) Comprehensive learning of Ruby's Module system, one of Ruby's most powerful features. #### File List: | File | Content | |------|---------| | `00_main.rb` | Main entry file, runs all module tests | | `01_module_basics.rb` | Module basics (constants, methods, instance methods, nesting) | | `02_namespace.rb` | Modules as namespaces (avoid naming conflicts, code organization) | | `03_mixin.rb` | Module mixins (include and extend usage) | | `04_debug_logger.rb` | Debug and Logger module implementation | | `05_enumerable.rb` | Enumerable built-in module (map, select, reduce, etc.) | | `06_comparable.rb` | Comparable built-in module (object comparison) | | `07_require_include.rb` | Differences between require, include, and extend | | `08_advanced_usage.rb` | Advanced module usage (interfaces, callbacks, singleton pattern) | | `09_comprehensive.rb` | Comprehensive practical examples | **Core Concepts:** - **Module Definition**: Module constants, module methods, instance methods - **Namespaces**: Organize code, avoid conflicts - **Mixin**: include (instance methods) vs extend (class methods) - **Built-in Modules**: Enumerable, Comparable - **Advanced Features**: included hooks, Refinements, dynamic creation **How to Run:** ```bash # Run all module tests cd module_test ruby 00_main.rb # Run a single test ruby 01_module_basics.rb ``` --- ### 4. Windows API Calling (`ruby_win32/`) Learn how to call Windows API using Ruby for system-level functionality. #### File List: | File | Content | |------|---------| | `01_messagebox.rb` | Call MessageBox API (various dialog types) | | `02_virtualalloc.rb` | Call VirtualAlloc API (memory management) | **Technical Points:** - Using Fiddle library to call Windows DLLs - UTF-16LE wide character encoding handling - Memory allocation and management - Windows API function signatures and parameter types **How to Run:** ```bash cd ruby_win32 ruby 01_messagebox.rb # Display various message boxes ruby 02_virtualalloc.rb # Memory allocation examples ``` ⚠️ **Note**: These examples only work on Windows systems. --- ### 5. TCP Network Programming (`ruby_net/`) Complete TCP client-server communication examples for learning network programming basics. #### File List: | File | Content | |------|---------| | `server.rb` | TCP server (multi-threaded, concurrent connection handling) | | `client.rb` | TCP client (connection, send messages, receive replies) | **Features:** - Multi-threaded concurrent handling of multiple clients - UTF-8 encoding support for Chinese character transmission - Complete exception handling and connection management - Interactive command-line interface **How to Run:** ```bash # Terminal 1: Start server cd ruby_net ruby server.rb # Terminal 2: Start client (can start multiple) ruby client.rb ``` --- ## 🎯 Recommended Learning Path ### Beginners (1-2 weeks) 1. Read basic concepts 2. Run basic syntax examples 3. Modify code manually and observe changes ### Intermediate Learning (2-4 weeks) 1. Deep dive into module system 2. Understand Mixin mechanism 3. Master Enumerable and Comparable modules ### Advanced Applications (Learn as Needed) 1. Windows API calling (system programming) 2. Network programming (TCP/UDP) 3. Metaprogramming and reflection --- ## 📝 Code Features ### Detailed Comments All code includes detailed Chinese comments explaining: - Syntax meaning - Parameter descriptions - Return value explanations - Usage examples - Important notes ### Practice-Oriented Every example can be run directly with clear output, suitable for: - Understanding concepts - Debugging and verification - Extension and modification ### Progressive Learning Content progresses from shallow to deep, from basic to advanced, suitable for: - Zero-basics beginners - Systematic learning - Reference lookup --- ## 🔧 Environment Requirements ### Ruby Version - Ruby 2.5+ (Ruby 3.x recommended) ### Dependencies #### Basic Tutorial and Module Tests - No additional dependencies needed, uses Ruby standard library #### Windows API Examples ```bash # Fiddle is part of Ruby standard library, no installation needed # Optional: Win32API (deprecated, may be available on some older systems) gem install win32-api ``` #### Network Programming - Uses Ruby standard library's `socket`, no additional installation needed --- ## 📂 Project Structure ``` NEWTEST/ ├── README.md # Chinese version of this file ├── README.en.md # This file ├── ruby-tutorial.md # Basic tutorial document ├── ruby_tutorial/ # Basic syntax examples │ ├── 00_main.rb # Main entry │ ├── 01_variables.rb # Variables │ ├── 02_data_types.rb # Data types │ ├── 03_input_output.rb # Input/Output │ ├── 04_conditionals.rb # Conditionals │ ├── 05_loops.rb # Loops │ ├── 06_methods.rb # Methods │ └── 07_classes.rb # Classes and objects ├── module_test/ # Module system tutorial │ ├── 00_main.rb # Main entry │ ├── 01_module_basics.rb # Module basics │ ├── 02_namespace.rb # Namespaces │ ├── 03_mixin.rb # Mixin mechanism │ ├── 04_debug_logger.rb # Debug and logging │ ├── 05_enumerable.rb # Enumerable module │ ├── 06_comparable.rb # Comparable module │ ├── 07_require_include.rb # require vs include │ ├── 08_advanced_usage.rb # Advanced usage │ └── 09_comprehensive.rb # Comprehensive examples ├── ruby_win32/ # Windows API examples │ ├── 01_messagebox.rb # Message boxes │ └── 02_virtualalloc.rb # Memory allocation └── ruby_net/ # Network programming examples ├── server.rb # TCP server └── client.rb # TCP client ``` --- ## 🚀 Quick Start ### 1. Clone or Download Project ```bash # If using git git clone cd NEWTEST # Or extract downloaded files directly cd NEWTEST ``` ### 2. Check Ruby Version ```bash ruby --version ``` ### 3. Run Your First Example ```bash cd ruby_tutorial ruby 00_main.rb ``` ### 4. Start Learning - Start by reading `ruby-tutorial.md` - Run example code in `ruby_tutorial/` - Gradually learn advanced features in `module_test/` - Explore practical applications in `ruby_win32/` and `ruby_net/` --- ## 💡 Learning Tips 1. **Hands-on Practice**: Don't just read, make sure to run and modify the code 2. **Experiment and Explore**: Try modifying parameters and observe output changes 3. **Write Comments**: Add comments in your own words to deepen understanding 4. **Build Projects**: Try writing small projects using what you've learned 5. **Consult Documentation**: Check official documentation when you encounter problems --- ## 📖 Recommended Resources ### Official Documentation - [Ruby Official Website](https://www.ruby-lang.org/) - [Ruby Core Documentation](https://docs.ruby-lang.org/) - [Ruby API Documentation](https://ruby-doc.org/) ### Community Resources - [Ruby China](https://ruby-china.org/) - Chinese Ruby community - [Ruby Monstas](https://rubymonstas.org/) - Free online tutorial - [Launch School](https://launchschool.com/) - Systematic learning - [Ruby Forum](https://forum.ruby-lang.org/) - Official Ruby forum ### Book Recommendations - "The Ruby Programming Language" - Authoritative reference - "Metaprogramming Ruby" - Advanced features - "Ruby on Rails Tutorial" - Web development - "Eloquent Ruby" - Best practices and idioms --- ## 🤝 Contributing Contributions are welcome: - Report bugs - Suggest new topics - Submit code improvements - Improve documentation --- ## 📄 License This project is for learning and reference purposes only. --- ## 🎓 Target Audience - Ruby beginners - Developers wanting to systematically learn Ruby - Programmers needing Ruby code examples - Educators teaching Ruby --- **Happy Learning! Happy Coding! 🎉**