Know what errors lurk in your code? Rollbar detects and alerts you when code breaks in production. Get the stack trace, code, and data to help you d̶e̶b̶u̶g̶ defeat Ruby errors. Learn more.

RubyFlow The Ruby and Rails community linklog


The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

OpenStruct 2

I just launched ostruct2 gem intended as drop in replacement for Ruby’s standard ostruct.rb library. The original OpenStruct class has some short-comings, such as name conflicts with built-in methods. OStruct2 improves upon the original by subclassing BasicObject to ensure a clean slate and adds some additional niceties such as support for Enumerable. This is v0.1.0. I’m sure it needs a little bit more work to be complete (e.g. #hash and #dup methods are probably unavoidable), but all the primary functionality is green.


Interesting implementation. Do you think it is a good idea to expose internal state(@table) when using bang! methods? If the implementation of @table changes in the future code that relies upon it may be broken. That’s why it might be better to only provide a public interface that manipulates internal data structures.

Anytime I see code trying to clean up standard lib, I say bravo!

@robgleeson @table is not exposed, I don’t see where it is.

@robogleeson You are right. I mention this issue in the current docs. Ultimately there needs to be some interface between the method_missing-handled bang methods and the underlying table, however I haven’t yet figured out the best approach. It would be nice if there were a way to do it dynamically rather than having to write a delegating method for every single possibility. I will get to this as soon as I can. If you have any suggestions for handling please let me know. In the mean time, I do not think it will matter for most use cases, which is why I decided it was okay for initial release.

@jim It’s exposed in #method_missing if you use a bang method that is not defined it will delegate it to the underlying table.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in