# Machine Learning in Ruby: Train, Check and Reload a Ruby-FANN Network: runnable files

4 tests / 16 assertions of actual native FANN training and reload on Ruby 3.3.2 with a disclosed local patch to ruby-fann 2.0.2; XOR fixture only.

Download all files in this folder before running. The article is at https://oneruby.dev/integrating-machine-learning-with-ruby-a-practical-guide/.

## Local patched dependency

Requires Ruby 3.3.2 and a working C build toolchain. The upstream 2.0.2 build failed with modern Clang; this is a two-location compatibility patch, not an upstream release. Use a new project-specific gem directory. The build script validates the original package SHA256 before extraction. It creates 2.0.2.oneruby1 so it cannot be confused with the unmodified upstream gem.

```sh
export GEM_HOME="$PWD/vendor/gems"
export GEM_PATH="$GEM_HOME"
gem fetch ruby-fann --version 2.0.2
ruby build_patched_gem.rb ruby-fann-2.0.2.gem patched
gem install --local patched/ruby-fann-2.0.2.oneruby1.gem --no-document
gem install bundler --version 2.7.0 --no-document
gem install minitest --version 6.0.6 --no-document
bundle install --local
bundle exec ruby test_example.rb
bundle exec ruby example.rb
```

The locally installed gem satisfies Gemfile.lock; version 2.0.2.oneruby1 is not available from RubyGems. Leave the compiler diagnostics enabled. Do not load untrusted network files.

## Files

- [Gemfile](Gemfile)
- [Gemfile.lock](Gemfile.lock)
- [build_patched_gem.rb](build_patched_gem.rb)
- [example.rb](example.rb)
- [test_example.rb](test_example.rb)

## Boundaries

- A local 2.0.2.oneruby1 compatibility build changes two C signatures; no upstream patch claim or general Ruby ABI certification.
- XOR truth-table fitting only; no held-out generalization evidence or real application model.
- FANN random initialization may produce different accepted predictions; bounded unsuccessful attempts raise.
- Serialization only of locally produced trusted network files; feature preprocessing is not encoded in this network file.
