It is useful when:
- There is a need for a Struct class that works consistently across esoteric implementations of Ruby like Opal. This is useful when writing cross-Ruby apps like those of Glimmer relying on YASL (Yet Another Serialization Library) in Opal.
- There is a need to meta-program Struct's data
- There are no big performance requirements that demand native Struct
In all other cases, stick to native Ruby Struct instead since it's optimized for performance.
gem install pure-struct
Or add to Gemfile:
gem 'pure-struct', '~> 1.0.2'
gem 'pure-struct', '~> 1.0.2', require: false
Finally, require in Ruby code:
Note that it removes the native
Struct implementation first, aliasing as
NativeStruct should you still need it, and then redefining
Struct in pure Ruby.
if RUBY_ENGINE == 'opal' require 'pure-struct' end
Contributing to pure-struct
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
- Fork the project.
- Start a feature/bugfix branch.
- Commit and push until you are happy with your contribution.
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright (c) 2021 Andy Maleh.