RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  
 

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.

Comments

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.robgleeson - May 21, 2012 06:54
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.jim - May 21, 2012 18:52
@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.trans - May 21, 2012 21:30
@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.trans - May 21, 2012 21:32

Post a Comment

Comment abilities for non registered users are currently deactivated, pending time to add a proper CAPTCHA to solve the escalating spam problem. Sorry!